如何在角2的ui-router中使用`otherwise`?

时间:2016-10-26 03:36:33

标签: javascript angularjs angular angular-ui-router

在ui-router中,我们可以添加$route['(:any)'] = "welcome/$1"来处理无效/未注册状态。这里是AngularJS

otherwise

意思是,每个无效的网址最终会转到$urlRouterProvider.otherwise('/index'); 。我们如何在ui-router中为Angular 2做同样的事情?我已经在'/index'的{​​{1}}使用了UIRouterModule.forRoot()UIRouterModule.forChild()

imports

2 个答案:

答案 0 :(得分:6)

UIRouterModule.forRoot docs显示了如何使用UIRouterModule.forRoot({ states: [loginState], otherwise: '/index' }), UIRouterModule.forChild({ states: [homeState] }) 属性的示例:

{{1}}

答案 1 :(得分:0)

您实际上将$ urlRouterProvider与$ stateProvider

结合使用

因此,首先您需要使用$ stateProvider

定义您的状态
 $stateProvider
    .state("otherwise", { url : '/index'...})

然后在$ urlRouterProvider上设置。来自我们首先定义的状态的URL

$urlRouterProvider
        .otherwise('/index');