UI-路由器——每次路由变化时运行函数——状态名称在哪里?时运、路由、路由器、函数

由网友(-結束的虛僞%)分享简介:Using Angularjs and UI-Router, trying to run a function every time state changes$rootScope.$on('$stateChangeStart',function(toState){if(toState !== 'login')User...

Using Angularjs and UI-Router, trying to run a function every time state changes

$rootScope.$on('$stateChangeStart',
        function(toState){
            if(toState !== 'login')
            UsersService.redirect();
        })

I put this in .run() and i can successfully log out toState every time route changes. However, i can't seem to find the property which has the name of the state that we are going to. If someone can tell me where to find that, i think i should be in good shape.

解决方案 水星无线路由器设置 如何设置路由器

Ended up with this and it does what i want.

$rootScope.$on('$stateChangeStart',
        function(event, toState, toParams, fromState, fromParams){
            if(toState.name !== 'login' && !UsersService.getCurrentUser()) {
            event.preventDefault();
            $state.go('login');
            }
        });

阅读全文

相关推荐

最新文章