I am testing this example about login registration in angular stackblitz The problem is that when you are logged in and you refresh the page on browser authguard redirects to login page. I have to fix this and redirect to current page. Hope anybody can help with this. Thanks.
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const currentUser = this.authenticationService.currentUserValue;
if (currentUser) {
// authorised so return true
return true;
}
else {
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }
});
return false;
}
}
It's working as of now, i just made the router navigate code to go in else
part .Check the stackblitz
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.