将ui router 0.2替换为1.0.0

时间:2016-06-13 10:01:28

标签: angularjs angular-ui-router

我已将ui-router v0.2升级到1.0.0但我的现有代码存在一些问题。所以我在官方文档中读到了

$rootScope.$on('$stateChangeStart'

现已替换为$transitions.onStart({},

$rootScope.$on('$stateChangeSuccess'

$transitions.onSuccess({},相同

到目前为止一切顺利。但在我的原始代码中,我有以下内容:

$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
   // some code here
   $state.go(toState.name, toParams);
}

我尝试了以下内容:

$transitions.onStart({}, function (toState, toParams) { 
     $state.go(toState, toParams);
}

toStatetoParams不可用......我查看了文档,但无法弄清楚我应该在这做什么。任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:1)

文档位于此处:http://angular-ui.github.io/ui-router/feature-1.0/您可以针对特定方案设置特定回调:

$transitionsProvider.onBefore({ to: 'my.state', from: '*' }, function(AsyncService) {
  return AsyncService.doSomeAsyncThing();
});