在Angular 1.5中刷新浏览器时如何保留相同的页面?

时间:2017-03-29 08:51:17

标签: javascript angularjs angular-components angular-component-router

在我的项目中,路由器设置如下:

   myApp.component("rsapproot", {
        transclude: true,
        template: "<ng-transclude></ng-transclude>",
        $routeConfig: [
            { path: "/login", component: "rsapplogin", name: "Login" },
            { path: "/tenant", component: "rsapptenantid", name: "Tenant" },
            { path: "/my-dashboard", component: "rsappmyrdash", name: "MyDash" },
            { path: "/my-reports", component: "rsappmyreports", name: "AppReports"},
            { path: "/equipment-details/:type/:id", component: "rsequipmentdetails", name: "EquipmentDetails" },
            { path: "/my/resources", component: "rsappresourceslist", name: "AppResourceList" },

现在预期在F5之后或粘贴URL时的行为分别是重新加载或导航到所述路径,而是加载初始应用程序路径。

我知道为了在重新加载应用后保留页面,应该提供代表路径的网址。

但是那个东西已经存在并且路径分别都是唯一的。

然后我错过了什么?

1 个答案:

答案 0 :(得分:2)

这需要在服务器端处理。这是一个说明当前问题的例子:

您可以在初始路径/加载应用,然后导航到/login。当您刷新页面时,您的Web浏览器会向http://yourdomain.com/login发送一个GET请求(我假设)通过将您的Angular应用程序(index.html)发送给客户端而没有响应。

您需要将服务器配置为使用index.html响应所有指定Angular路径的GET请求。这通常使用全部路由/*来完成,而不是单独指定每个路由。