由网友(-結束的虛僞%)分享简介:Using Angularjs and UI-Router, trying to run a function every time state changes$rootScope.$on('$stateChangeStart',function(toState){if(toState !== 'login')User...![水星无线路由器设置 如何设置路由器](https://p.xsw88.cn/allimgs/daicuo/20230906/1810.png)
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.
解决方案![水星无线路由器设置 如何设置路由器](https://p.xsw88.cn/allimgs/daicuo/20230906/1810.png)
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');
}
});
相关推荐
最新文章