stop angular-ui-router navigation until promise is resolved

前端 未结 10 1947
情歌与酒
情歌与酒 2020-12-01 02:44

I want to prevent some flickering that happens when rails devise timeout occurs, but angular doesn\'t know until the next authorization error from a resource.

What h

10条回答
  •  日久生厌
    2020-12-01 03:15

    I ran in to the same issue Solved it by using this.

    angular.module('app', ['ui.router']).run(function($rootScope, $state) {
        yourpromise.then(function(resolvedVal){
            $rootScope.$on('$stateChangeStart', function(event){
               if(!resolvedVal.allow){
                   event.preventDefault();
                   $state.go('unauthState');
               }
            })
        }).catch(function(){
            $rootScope.$on('$stateChangeStart', function(event){
               event.preventDefault();
               $state.go('unauthState');
               //DO Something ELSE
            })
    
        });
    

提交回复
热议问题