【问题标题】:Angularjs ui.router 404 not found pageAngularjs ui.router 404 找不到页面
【发布时间】:2017-08-10 18:21:16
【问题描述】:

我的 stateProvider Angular 代码

 .state('profile',{
    url: '/profile',
    templateUrl: 'Templates/profile.html',
    controller: 'profileCtrl'
})


 .state('profile.details',{
        url: '/:id',
        templateUrl: 'Templates/profile.details.html',
        controller: 'profileCtrl'
    })

当我在 chrome 栏中写这个时 http://localhost/site/profile/1

Apache 响应是 在此服务器上找不到请求的 URL /site/profile.html/1。

但如果我点击 ui-sref 链接,它会很好地打开

【问题讨论】:

标签: angularjs


【解决方案1】:

因为您使用的是客户端路由,所以您使用的任何服务器端技术(Node.js、Rails、Django、ASP.NET ......)都有责任拥有*(包罗万象)接受所有内容并仅渲染相同内容的路由(您的 HTML 与 bundle.js)并让客户端决定要渲染的内容。

【讨论】:

  • 另外值得注意的是,如果$locationProvider 设置启用了hashPrefix 并禁用了html5Mode,则该url 还需要其中的前缀才能在首次加载url 或刷新时路由到正确的状态通过浏览器访问的页面。
  • 这是我的演示链接link 点击登录并刷新页面,我将我的 html5mode 更改为 false,但它不起作用。
猜你喜欢
  • 1970-01-01
  • 2013-06-28
  • 2016-08-01
  • 2016-08-01
  • 2015-10-22
  • 2014-03-20
  • 2020-10-27
  • 2019-07-21
  • 2020-07-14
相关资源
最近更新 更多