Angular ui-router $state.go is not redirecting inside resolve

后端 未结 6 959
刺人心
刺人心 2021-02-05 04:57

In my angularjs app, I am checking if user lands on landing page and is already authenticated, then redirect him to home page.

.state(\'landingpage\', {
                 


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 05:29

    Anyway resolve waiting for promise state . Best thing what you can do is return promise and add timeout for your state:

    resolve: {
        AutoLoginCheck: ['$state', '$window', '$timeout', '$q', function ($state, $window, $timeout, $q) {
            var deferred = $q.defer();
            if(user.isLogin()){
                 deferred.resolve();
            }else{
              $timeout(function(){
                $state.go('app.home');
              }
              deferred.reject();
            }
            return deferred.promise;
        }]
    

提交回复
热议问题