this has been posted many times but I'm still not having luck with this:
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
if (error && !error.authenticated) {
$location.path('/login');
console.log('new path: ' + $location.path());
}
});
My app will in fact not go to /login
, yet the console.log will return a value of /login
. I've tried the $apply
trick without luck mentioned in other threads but this is a very simple app at this point, no third party integrations where angular needs some additional help via $apply
. Is there a variant to $location.path()
needed when used within the context of $rootScope
, or listening for $stateChangeError
?
I'm sure this is something simple and I'm just not seeing it.
I failed to mention I'm using ui.router and so switching to $state.go('login')
seemed to make it work. Next time I will make sure to post a plunker to get something reproducible and perhaps solve my own problem :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.