Why does $state.transitionTo or $state.go does not display the new HTML partial?

后端 未结 3 1629
独厮守ぢ
独厮守ぢ 2021-01-22 09:22

Here is a piece of code destined to check user rights before each UI-router state change. Everything works fine, except the fact that when rights are OK, the transition to the n

3条回答
  •  天命终不由人
    2021-01-22 09:51

    I had a similar issue and this is how I solved it:

    if( AuthManager.isUserConnected() ) {
       //...
       event.preventDefault();
       $state.go(toState.name, null, {notify: false}).then(function (state) {
          $rootScope.$broadcast('$stateChangeSuccess', state, null);
       });
    }
    

    As it's mentioned in other answers, $state.go doesn't work propertly in .run. Following the advises of this thread I ended up working with this workaround

    $urlRouterProvider.otherwise(function ($injector) {
       var $state = $injector.get('$state');
       $state.go('/home');
    });
    

    Not sure if this could help you, but you could try it. Hope it helps

提交回复
热议问题