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

后端 未结 6 1614
没有蜡笔的小新
没有蜡笔的小新 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:04

    Looks like this is a bug with ui-router when you use the combination of $urlRouterProvider.otherwise("/foo) with the $stateChangeStart.

    Issue - https://github.com/angular-ui/ui-router/issues/600

    Frank Wallis provides a nice workaround, use the longer form of the otherwise method that takes a function as an argument:

    $urlRouterProvider.otherwise( function($injector, $location) {
                var $state = $injector.get("$state");
                $state.go("app.home");
            });
    

    Nice work Frank!

提交回复
热议问题