Angular Route Guards

Angular 278 views Nov 14, 2025 1 min read

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
Share this Post
🚀 Want to Test Your Knowledge?

Take quizzes related to this topic and see where you stand!

Start Quiz Now
Back to Tutorials