Angular UI路由器匹配错误的路由

时间:2017-12-05 15:48:42

标签: angularjs angular-ui-router

我的应用有3条路线(html5模式):

/app/home
/app/foo
/something-random

然后如果没有匹配则回退到/ app / home。这些定义如下:

$stateProvider
            .state('app', {
                url: '/app',
                abstract: true,
                templateUrl: 'frame.html',
                controller: 'frame'
            })
            .state('app.home', {
                url: '/home',
                params: {
                    scrollTo: null
                },
                views: {
                    sectionHolder: {
                        templateUrl: 'home.html',
                        controller: 'home'
                    }
                }
            })
            .state('app.foo', {
                url: '/foo',
                params: {
                    scrollTo: null
                },
                views: {
                    sectionHolder: {
                        templateUrl: 'foo.html'
                        controller: 'foo'
                    }
                }
            })
            .state('extra', {
                url: '/:slug',
                templateUrl: 'extra.html',
                controller: 'extra'
            });

$urlRouterProvider.otherwise('/app/home');

结果如下:

mysite.com/app/home            ->   works
mysite.com/app/foo             ->   works
mysite.com/something-random    ->   works
mysite.com                     ->   matches the extra route and does not fallsback to /app/home as intended.

根据documentation

  

' /用户/:ID' - 匹配' / user / bob'或者' / user / 1234 !!!'甚至' / user /'   但不是' / user'或' / user / bob / details'。第二个路径段将   被捕获为参数' id'。

但在我的情况下是匹配一个空的slu ..

0 个答案:

没有答案
相关问题