I have an Angular app using UI Router where I\'m trying to validate a user\'s token, if one exists, when the app runs. I am also checking that the user has permission to acc
I guess it's too late for answering this question, but I want to comment here for someone who may need a little idea.
I've tried to do almost same thing for a long time and I stopped doing that. I don't think stateChangeStart
listener is reliable to use.
I think the best way to do your what you want is decorating $state.go
using $provide
service. Here is an example:
/* config your angular app */
.config(function($provide) {
$provide.decorator('$state', function($delegate) {
var myState = $delegate;
// Rename original 'go' method
myState.originalGo = myState.go;
myState.go = function(toState, toParams, options) {
/*
* Do what you want to do :)
*/
this.originalGo(toState, toParams, options);
};
return $delegate;
});
With this approach, you can do whatever you want before $stateChangeStart
.
I hope it helps.