I have an application, the first screen is the login screen.
The goal is to skip this screen if the user have a session on the server.
I can check for the session in app.run() function but i can’t change location from this function.
I can go to the main screen from the login screen but the user can see the login screen during 0.1 second and i don’t like it
What is the good practice to do this ?
maybe can i force location routing in app.run() ?
maybe can i change view from login screen before this screen appear ?
@rdb, you can change the location from the app.run() function.
You have to inject $state to the run function.
Then, you can check whatever you want (authentication stuff - session on the server, etc.) and redirect the user to the relevant state.
For example, if there is no session on the server, you call $state.go(‘app.login’); where ‘app.login’ is a state defined in your config function.
Yes but when the app handle the server response the app is ready and i am in the login page, at this point $location don’t work. I made differently :
when the Login page appear i display an overlay on the app with a loader. After server response, if connected we go in app, else I let the user login.
( I don’t use UI Router so my routing object is not $state but $location )
Thanks for reponse @meni I think your idea work if the request in app.run is synchronous, else response come too late.
That looks interesting, what i made is an overlay in the landing page during checking authentication, with that its possible to show a css animation