home / skills / hoangnguyen0403 / agent-skills-standard / routing
This skill guides Angular routing best practices by enforcing lazy loading, functional guards, and route data binding for robust apps.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill routingReview the files below or copy the command above to add this skill to your agents.
---
name: Routing
description: Standards for Angular Router, Lazy Loading, and Guards.
metadata:
labels: [angular, routing, guards, lazy-loading]
triggers:
files: ['*.routes.ts']
keywords: [angular router, loadComponent, canActivate, resolver]
---
# Routing
## **Priority: P0 (CRITICAL)**
## Principles
- **Lazy Loading**: Use `loadComponent` for standalone components and `loadChildren` for route files.
- **Functional Guards**: Use function-based guards (`CanActivateFn`) instead of class-based guards (Deprecated).
- **Component Inputs**: Enable `withComponentInputBinding()` to map route params directly to component inputs.
## Guidelines
- **Title Strategy**: Use `TitleStrategy` service to auto-set page titles from route data.
- **Resolvers**: Use `resolve` to pre-fetch critical data before navigation completes, but avoid blocking UI for too long.
## Anti-Patterns
- **Logic in Routes**: Keep route definitions clean. Move logic to Guards or Resolvers.
- **Eager Loading features**: Never direct import feature components in root routes.
## References
- [Routing Patterns](references/routing-patterns.md)
This skill documents routing standards for Angular projects, focusing on lazy loading, functional guards, and clean route definitions. It prescribes patterns that improve load performance, maintainability, and predictable navigation behavior. The guidance targets TypeScript-based Angular apps and standalone component patterns.
The skill inspects route configuration and recommends using loadComponent or loadChildren to enable lazy loading and avoid eager imports. It enforces function-based guards (CanActivateFn and related APIs) and suggests withComponentInputBinding() to map route params to component inputs. It also recommends TitleStrategy for automatic titles and resolve for essential pre-fetching.
When should I use loadComponent vs loadChildren?
Use loadComponent for lazy-loading standalone components. Use loadChildren when lazy-loading an NgModule or a route file that exports multiple routes or providers.
Are class-based guards still supported?
They may still work in older code, but prefer functional guards (CanActivateFn, CanLoadFn) because class-based guards are deprecated and functional APIs are simpler and tree-shakable.