nolines nolines - 4 months ago 5x
AngularJS Question

How to prevent user to change state of route before some processes

I have Principle factory that set and get user value from local storage after login. But when the user first logged in Principle factory return firstLogin = true, if the user first logged in user must update their company. Because while registering process, the application creates an empty company model and I have to update it with source and addresses information at the first login.

So, how could I prevent user to change state by clicking over URL hrefs at navigation?


I already tried to add ng-disable= 'firstLogin' but i have a lot of states of the application. Thank you.


You can use $stateChangeStart or $routeChangeStart depending whether you are using ui-router or ng-router respectively.

You can run some functions like checking for auth etc before a state/route change occurs. Please check the examples in the docs linked.