Angular Route Guards

📘 Angular 👁 138 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

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes

🤖 AI Quizer Assistant

📝 Quiz
📚 Categories
🏆 Leaderboard
📊 My Score
❓ Help
👋 Hi! I'm your AI quiz assistant for Quizer.in!

I can help you with:
• 📝 Finding quizzes
• 🏆 Checking leaderboard
• 📊 Your performance stats

Type 'help' to get started! 🚀
AI is thinking...