angularjs ui-router:为同一状态重定向vs多个url

时间:2017-03-16 14:00:49

标签: angularjs angular-ui-router

当我首先导航到我的索引页面,其中网址为' /'时,我想显示州的内容' /匹配'。您认为哪个更好?

我可以用

$urlRouterProvider.otherwise('/matches'); 这有效,但我知道这不是一个好的解决方案。

所以我必须在

之间做出选择

1-将/重定向到/matches,我尝试了

$urlRouterProvider.when('/','/matches'); 但它没有用。

2-指定多个路径//matches到相同的状态匹配,我不知道该怎么做。

在ng-route中,我曾经这样做过:

.when('/', {
    redirectTo : '/matches'
})

但我认为将ng-route与ui-router结合起来并不好。

1 个答案:

答案 0 :(得分:0)

我找到了一个完美的解决方案

 app.run(function($state){
  $state.go('/matches');
 });

应用程序运行后,我使用 $ state.go 调用我要加载的状态,并且还保留了

$urlRouterProvider.otherwise('/matches');

如果用户试图输入无效的网址(状态),他将被重定向到初始状态。