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

后端 未结 6 964
刺人心
刺人心 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条回答
  •  滥情空心
    2021-02-05 05:39

    .state('landingpage', {
                abstract: "true",
                url: "/landingpage",
                templateUrl: "app/landingpage/landingpage.html",
                resolve: {
                    AutoLoginCheck: ['$state','$window', '$q','$timeout', function ($state, $window,$q,$timeout) {
    
                        if($window.localStorage.access_token != null)
                        {
                            if($window.sessionStorage.access_token == null) {
                                $window.sessionStorage.access_token = $window.localStorage.access_token;
                            }
                            UserInfoService.SetUserAuthenticated(true);
    
    
                            $timeout(function() {
                               $state.go('app.home')
                            },0);
                            return $q.reject()
    
                        }
                    }]
                }
            })
    

    This would work for you.

提交回复
热议问题