Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to referer

Tags:

angularjs

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?

like image 956
Max Avatar asked Aug 22 '12 06:08

Max


Video Answer


1 Answers

You can use $rootScope or define a service to save the old location. Here is a SO post that contrasts the two approaches. I personally don't like adding returnto= 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.

like image 81
Mark Rajcok Avatar answered Sep 28 '22 11:09

Mark Rajcok