Why does AngularJS with ui-router keep firing the $stateChangeStart event?

后端 未结 6 1606
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 18:29

I\'m trying to block all ui-router state changes until I\'ve authenticated the user:

$rootScope.$on(\'$stateChangeStart\', function (event, next, toParams) {         


        
6条回答
  •  一整个雨季
    2020-12-04 19:18

    Fakeout. This is an interaction issue between $urlRouterProvider and $stateProvider. I shouldn't be using $urlRouterProvider for my otherwise. I should be using something like:

    $stateProvider.state("otherwise", {
        url: "*path",
        template: "Invalid Location",
        controller: [
                  '$timeout','$state',
          function($timeout,  $state ) {
            $timeout(function() {
              $state.go('/foo')
            },2000)
          }]
    });
    

    Or even a transparent'ish redirect:

    $stateProvider.state("otherwise", {
        url: "*path",
        template: "",
        controller: [
                  '$state',
          function($state) {
            $state.go('/foo')
          }]
    });
    

    Altogether now:

    
      
        
        
        
      
      
        

提交回复
热议问题