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

sig*_*oga 3 javascript angularjs angular-ui-router angular

在ui-router中,我们可以添加otherwise处理无效/未注册状态.这是在AngularJS中

$urlRouterProvider.otherwise('/index');
Run Code Online (Sandbox Code Playgroud)

这意味着,每个无效的URL '/index'最终都会到达.我们如何在ui-router中为Angular 2做同样的事情?我已经使用了UIRouterModule.forRoot()和UIRouterModule.forChild()中imports的app.module.ts.

UIRouterModule.forRoot({ states: [loginState] }),
UIRouterModule.forChild({ states: [homeState] })
Run Code Online (Sandbox Code Playgroud)

Chr*_*s T 6

该UIRouterModule.forRoot文档显示了如何使用一个例子otherwise属性:

UIRouterModule.forRoot({ states: [loginState], otherwise: '/index' }),
UIRouterModule.forChild({ states: [homeState] })
Run Code Online (Sandbox Code Playgroud)