In AngularJS, I have a login controller that is redirected to by every single page in the app if the user arrives at the page and is not logged in. After the login sequence, I would like to redirect the user back to the page that they came from. What’s the best way to do this? Save the old location in the $rootScope? Redirect to '/login?returnto=' + $location.path()? Is there a built in function?
In AngularJS, I have a login controller that is redirected to by every single
Share
You can use
$rootScopeor define a service to save the old location. Here is a SO post that contrasts the two approaches. I personally don’t like addingreturnto=to the URL.This blog post, Authentication in AngularJS, might be of interest to you. Note the comment that Vojta (one of AngularJS authors) made on that blog post about using
$rootScope— he recommends a service instead.