angular-guards

Implement functional Angular route guards for v21 and later.

6|1|Updated Feb 18, 2026
One-click install
npx skills add https://github.com/oguzhan18/angular-ecosystem-skills --skill angular-guards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: angular-guards
Source: https://github.com/oguzhan18/angular-ecosystem-skills/tree/main/skills/angular-guards
Command: npx skills add https://github.com/oguzhan18/angular-ecosystem-skills --skill angular-guards

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Protects Angular application routes by providing clear patterns, migration guidance, and practical implementations for route authorization and navigation control so teams can prevent unauthorized access and accidental navigation loss.

Core Features & Use Cases

  • Functional Guard Patterns: Examples and recommendations for CanActivateFn, CanDeactivateFn, CanMatch, and CanActivateChild to replace deprecated class-based guards.
  • Lazy-loading & Authorization: Techniques to use CanMatch and provideRouter to avoid loading unauthorized code and to protect lazy-loaded routes.
  • Common Workflows: Protecting dashboards and admin areas with role checks, prompting users on unsaved changes via CanDeactivate, and combining multiple guards for layered security.

Quick Start

Generate functional CanActivate and CanMatch guard implementations for the project's admin and dashboard routes and provide migration steps from any class-based guards found.

Frequently Asked Questions about angular-guards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate Angular class-based guards to functional guards?

To migrate Angular class-based guards to functional guards, you replace class implementations with CanActivateFn, CanDeactivateFn, and CanMatch functional patterns, then register them through provideRouter for v21 and later projects.

What is the difference between CanActivate and CanMatch in Angular routing?

CanActivate checks authorization before route navigation, while CanMatch controls whether lazy-loaded route code loads at all. CanMatch prevents unauthorized code from loading, whereas CanActivate evaluates access permissions for route activation.

How do I protect lazy-loaded routes in Angular from unauthorized access?

Protect lazy-loaded Angular routes by applying CanMatch functional guards with provideRouter. This prevents unauthorized lazy-loaded code from being fetched, ensuring route protection and authorization checks happen before any code loads.

Can I use Angular guards to prompt users about unsaved changes?

Yes, use the CanDeactivate functional guard to prompt users about unsaved changes during navigation. It intercepts route exits, allowing you to warn users and prevent accidental data loss when leaving forms or workflows.

Do Angular functional guards support role-based route protection?

Angular functional guards support role-based route protection by implementing data-driven guard checks within CanActivateFn. You can combine multiple functional guards for layered security to protect dashboards and admin areas with specific role verification.