0

There is a case, if I get Unauthorized Error(401), it should redirect the Login page which I have defined in my interceptor to handle this error. After login, it should redirect the previous page where I got the 401 error.

I have followed this tutorial, quite helpful to me: http://jasonwatmore.com/post/2016/12/08/angular-2-redirect-to-previous-url-after-login-with-auth-guard.

But in the above tutorial, he didn't mention about redirection to login. So I have a question now, where should I store the route before the redirection to login. According to my knowledge, we cannot use the activatedRoute.snapshot in my interceptor.

Thanks in advance for helping.

grk
  • 31
  • 1
  • 3

1 Answers1

0

What you're looking for is the state of the @angular/route, read the documentation here: https://angular.io/api/router

Then if it's an instance of NavigationEnd you can store it into the localStorage. Answers and code samples are mentionned here: How to determine previous page URL in Angular?

kingabdr
  • 588
  • 5
  • 12