Angular Route Guards
📘 Angular
👁 93 views
📅 Nov 14, 2025
⏱ Estimated reading time: 1 min
Angular Route Guards
Route guards protect navigation in Angular applications. They prevent unauthorized access and control routing behavior.
Types of Route Guards
- CanActivate: Prevent unauthorized access.
- CanDeactivate: Confirm leaving a page.
- Resolve: Fetch data before navigating.
- CanLoad: Prevent lazy loading modules.
CanActivate Example
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService) {}
canActivate(): boolean {
return this.authService.isLoggedIn();
}
}
Usage in Routing
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] }
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials