angular route gaurds redirect code example
Example 1: angular guard redirect
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (!this.authService.isLoggedIn) {
return this.router.parseUrl('/notauthorized');
} else {
return true;
}
}
}
Example 2: how to add redirec router in angular
Angular Path Router Redirect