Route guards protect navigation in Angular applications. They prevent unauthorized access and control routing behavior.
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService) {}
canActivate(): boolean {
return this.authService.isLoggedIn();
}
}
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] }
Take quizzes related to this topic and see where you stand!
Start Quiz Now