ui-router root调用不可能?

时间:2016-09-12 09:18:30

标签: angularjs azure url-rewriting angular-ui-router angular-routing

我已经应用了ui-router路由,它运行得很好。

然而,当我将网站发布到azure时,我会在根页面上看到这个

enter image description here

导航到/ home url工作正常,所有其他网址都正常工作但我希望主根视图与/ home相同。

我怎样才能实现这一目标?

我正在使用Visual Studio空白项目,其中包含所有Angular功能。

ui-router logic:

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $urlRouterProvider.otherwise('/');

    $stateProvider
          .state('root', {
              url: '',
              data: {
                  css: [
                      '/assets/css/homepage.css',
                      {
                          name: 'layout1',
                          href: '/assets/css/bootstrap.min.css'
                      },
                      {
                          name: 'layout2',
                          href: '/assets/css/style.css'
                      },
                      {
                          name: 'layout3',
                          href: '/assets/css/responsive.css'
                      },
                      {
                          name: 'layout4',
                          href: '/assets/fonts/font-awesome/css/font-awesome.min.css'
                      }
                  ]
              },
              views: {
                  'header': {
                      templateUrl: '/views/partials/header.html'
                  },
                  'content': {
                      templateUrl: '/views/home/index.html',
                      controller: 'homeController'
                  },
                  'footer': {
                      templateUrl: '/views/partials/footer.html'
                  }
              }
          })
        .state("home", {
            url: "/",
            data: {
                css: [
                    '/assets/css/homepage.css',
                    {
                        name: 'layout1',
                        href: '/assets/css/bootstrap.min.css'
                    },
                    {
                        name: 'layout2',
                        href: '/assets/css/style.css'
                    },
                    {
                        name: 'layout3',
                        href: '/assets/css/responsive.css'
                    },
                    {
                        name: 'layout4',
                        href: '/assets/fonts/font-awesome/css/font-awesome.min.css'
                    }
                ]
            },
            views: {
                'header': {
                    templateUrl: '/views/partials/header.html'
                },
                'content': {
                    templateUrl: '/views/home/index.html',
                    controller: 'homeController'
                },
                'footer': {
                    templateUrl: '/views/partials/footer.html'
                }
            }
        })
        .state("ourteam", {
            url: "/ourteam",
            data: {
                css: [
                    '/assets/css/responsive.css',
                    '/assets/css/style.css'
                ]
            },
            views: {
                'header': {
                    templateUrl: '/views/partials/header.html'
                },
                'content': {
                    templateUrl: '/views/home/our-team.html'
                },
                'footer': {
                    templateUrl: '/views/partials/footer.html'
                }
            }
        })
        .state("contact", {
            url: "/contact",
            data: {
                css: [
                    '/assets/css/responsive.css',
                    '/assets/css/style.css'
                ]
            },
            views: {
                'header': {
                    templateUrl: '/views/partials/header.html'
                },
                'content': {
                    templateUrl: '/views/home/contact.html'
                },
                'footer': {
                    templateUrl: '/views/partials/footer.html'
                }
            }
        })
});

2 个答案:

答案 0 :(得分:0)

您可以发布代码段或至少发布ui-router配置吗?

PS:我认为用微软IDE创建一个google框架样板并不是最好的主意。如果您查看自己的代码并将其部分构建为自己,则最好先了解所发生的情况。

答案 1 :(得分:0)

根据https://github.com/angular-ui/ui-router/issues/185#issuecomment-19661148中的评论,""似乎是"/"的别名。

请尝试以下配置:

$urlRouterProvider.otherwise('/');

$stateProvider
    .state('root', {
          url: '/',
          ...
          })
    .state('home',{
          url:'/home',
          ...
          })