UI Router $ state.go not redirecting?

This is a common problem, I see a ton, but nothing works. That's what I'm doing. I want to have dynamic animations with my states, so basically the login will do some cool animations and go to the real interface. Now I started nested views as follows:

    $stateProvider
        .state('login', {
            url: '/login',
            title: "Login",
            views: {
                "master": {
                    controller: "LoginController",
                    templateUrl: "/components/login/login.html",
                    authentication: false
                }
            }
        })
        .state("logout", {
            url: "/logout",
            title: "Logout",
            authentication: false
        })
        .state('foo', {
            url: '/',
            controller: "HomeController",
            views: {
                "master": {
                    templateUrl: '/components/ui-views/masterView.html'
                },
                "sidebar@foo": {
                    templateUrl: '/components/sidebar/_sidebar.html'
                },
                "header@foo": {
                    templateUrl: '/components/header/_header.html'
                }
            }
        })
        .state('foo.inventory', {
            url: '/inventory',
            title: "Inventory",
            views: {
                "content@foo": {
                    controller: "InventoryController",
                    templateUrl: "/components/inventory/inventory.html"
                }
            }
        });

So while doing this I need to redirect to exit, but it is stuck. It will not move out of this exit state. Here is how I handle it:

function run($http, $rootScope, $cookieStore, $state, $templateCache, $timeout, AuthService, modalService, const) {
        var timeout;

        FastClick.attach(document.body);
        $rootScope.globals = $cookieStore.get('globals') || {};

if ($state.current.name !== 'login' && !$rootScope.globals.guid) {
            $state.go('login');
        } else if ($state.current.name == 'login' && $rootScope.globals.guid) {
            $state.go('foo');
        }

        $rootScope.$on('$stateChangeStart', function (event, next, current, fromState, fromParams) {
            var authorizedRoles = next.level != undefined ? next.level : 1,
                needAuth = next.authentication != undefined ? next.authentication : true;

            if (needAuth) {
                if (!AuthService.isAuthorized(authorizedRoles, true)) {
                    event.preventDefault();
                    if (AuthService.isAuthenticated()) {
                        $rootScope.$broadcast(const.auth.notAuthorized);
                        $state.go('foo', {});
                    } else {
                        $rootScope.$broadcast(const.auth.notAuthenticated);
                    }
                }
            }

            if (next.name == 'logout') AuthService.logout($rootScope.globals);
        });

}

So why doesn't it work? This seems to be a wonderful job. But $state.go('login')returns a bad value.

If anyone can direct me in the right direction or tell me exactly what is wrong.

+4
4

, $state.go , , . $state.go .

+7

. , ui-sref , , $state.go $timeout angular -ui.

var transition = $timeout(function() {
                debugger;
                $state.go("app.authentication");
            });

, . ( ui-sref , .)

+5

只 需要 升级 ui-router 版本 就 可以 了, 见 连接 地址: https://github.com/mattlewis92/angular-bluebird-promises/issues/11

ui-router 0.3.2, : angular -ui/ui-router @66ab048

+1

I ran into these problems in my application, you are trying to call $state.goin an internal ui-viewthat is not state related, that is, you ran into this problem, so try the following:

app.run(['$state', '$rootScope', '$timeout', 
function ($state, $rootScope, $timeout) {

 $timeout(function() { 
      $state.go('login');
    });   
}]);
0
source

All Articles