【问题标题】:AngularJS application shows file structure when I refreshAngularJS应用程序在我刷新时显示文件结构
【发布时间】:2017-03-19 01:15:52
【问题描述】:

我目前有一个 AngularJS 前端用于我的应用程序。我已经使用 ui-router 在状态之间进行转换。

当我启用 HTML5 模式并刷新页面时,应用程序最终会提供文件结构,而不是刷新的页面。

请告诉我我做错了什么。

我在下面给出了一些我的代码:

这些是我的状态定义:

.state('home', {
           url: '/home',
           views:{
             'home':{
               templateUrl: 'home/home.html',
               controller : 'HomeCtrl',
               controllerAs : 'homeCtrl'
             }
           },
           access:{restricted: true}
       })


       .state('quote',{
         url : '/quote',
         views: {
           'quote' : {
             templateUrl : 'quote/quote.html',
             controller : 'QuoteCtrl',
             controllerAs : 'quoteCtrl'
           }
         },
         access:{restricted: true}
       })
       .state('profile',{
         url : '/profile',
         views: {
           'profile' : {
             templateUrl : 'profile/userprofile.html',
             controller : 'ProfileCtrl',
             controllerAs : 'profileCtrl'
           }
         },
         access:{restricted: true}
       })

来自我的 app.js 的片段,我在其中启用了 html5mode:

$locationProvider.html5Mode({
       enabled: true,
       requireBase: false
       });

sn-p 来自我的 index.html:

<base href="/"/>

我还附上了我按 F5 时看到的文件结构的图片。

服务器背景:我在 AWS 服务器上运行我的网站并使用 NGINX + npm。

问候, 加利杰

【问题讨论】:

  • 这几乎可以肯定是 Web 服务器配置问题。在单页 Angular 应用程序中,所有路由都应该指向同一个入口点。我建议你展示你的 Nginx 配置。
  • 感谢您的意见,我们已经解决了

标签: angularjs html angular-ui-router


【解决方案1】:

我通过使用 express js 编写 server.js 脚本解决了这个问题。

参考:Html5Mode - refreshing the angularjs page issue

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

请参阅与快速重写相关的部分。

谢谢,

加利杰

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-22
    • 2016-09-06
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2020-07-19
    • 1970-01-01
    相关资源
    最近更新 更多