In the project I'm working on, it's common to pass links to details of a purchase on email, but when the user opens the link it asks for authentication in the system, but after logging in, it is redirected to the home page (the system panel) and not for the purchase details.
if (admin) {
that.router.navigate(['/main-panel'], { replaceUrl: true });
} else (seller) {
that.router.navigate(['/main-panel-seller'], { replaceUrl: true });
}
The only validation I do is where I'm going to send this user, there is any way to check the previous url? Or somewhere where I can find this url information is stored.
When you redirect the user to the login page you can pass the original url as params , and navigate to it when he's logged in
For example : in the auth gard
this.router.navigate(['login'], { queryParams: { returnUrl: state.url }});
and in the controller :
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
his.router.navigateByUrl(this.returnUrl);
(Source)