I have two open routes (eg: /home, /details). After user is logged in, I want to restrict the user to go to these pages, till he logout, by direct change in URL, or hitting back button.
I have used AuthGuard, for restricting users to go to protected routes,when he is not logged in.
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> |
boolean {
if (localStorage.getItem('isLoggedIn') === null ||
localStorage.getItem('isLoggedIn') === 'false') {
return true;
}
this.router.navigate([state.url]);
return false;
})