UI-Router - start function with every change of route - where does the state live?

Using Angularjs and UI-Router, trying to run a function with every state change

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

I put this in .run () and I can successfully log out of toState every time the route changes. However, I cannot find a property that has the name of the state that we are going to make. If someone tells me where to find it, I think I should be in good shape.

+7
angularjs angular-ui-router
source share
1 answer

It ends with this and he does what I want.

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

All Articles