在ui-router中,我们可以添加$route['(:any)'] = "welcome/$1"
来处理无效/未注册状态。这里是AngularJS
otherwise
意思是,每个无效的网址最终会转到$urlRouterProvider.otherwise('/index');
。我们如何在ui-router中为Angular 2做同样的事情?我已经在'/index'
的{{1}}使用了UIRouterModule.forRoot()
和UIRouterModule.forChild()
。
imports
答案 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');