Configure Angular routing with guards, resolvers, and lazy loading
✓Works with OpenClaudeYou are an Angular framework expert. The user wants to configure a complete Angular routing system with route guards, data resolvers, and lazy-loaded feature modules.
What to check first
- Run
ng versionto confirm Angular CLI is installed and your project Angular version - Verify
RouterModuleis imported in yourapp.module.tsor standaloneapp.config.ts - Check that feature modules exist or will be created with
ng generate module feature-name --routing
Steps
- Create a
CanActivateguard usingng generate guard guards/auth— this prevents unauthorized access to routes - Create a
Resolver<T>service usingng generate resolver resolvers/data— this preloads data before route activation - Define your routing configuration in
app.routes.ts(standalone) orapp-routing.module.ts(module-based) with theRoutesarray - Add lazy loading with
loadChildrenproperty pointing to feature module path using ESM syntax - Apply guards using the
canActivateproperty in route definitions, passing your guard class - Apply resolvers using the
resolveproperty, mapping resolver keys to resolver instances - Implement
Router.navigate()orrouterLinkdirective with route parameters and query strings - Handle navigation state with
ActivatedRoute.params,ActivatedRoute.queryParams, and resolver data viadataproperty
Code
// 1. Auth Guard (guards/auth.guard.ts)
import { Injectable } from '@angular/core';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
@Injectable({ providedIn: 'root' })
export class AuthGuard implements CanActivate {
constructor(private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
const isAuthenticated = !!localStorage.getItem('authToken');
if (!isAuthenticated) {
this.router.navigate(['/login']);
return false;
}
return true;
}
}
// 2. Data Resolver (resolvers/user-data.resolver.ts)
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
@Injectable({ providedIn: 'root' })
export class UserDataResolver implements Resolve<any> {
constructor(private http: HttpClient) {}
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const userId = route.paramMap.get('id');
return this.http.get(`/api/users/${userId}`);
}
}
// 3. Routing Configuration (app.routes.ts - Standalone API)
import { Routes } from '@angular/router';
import { AuthGuard
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Angular Skills
Other Claude Code skills in the same category — free to download.
Angular Component
Create Angular components with inputs, outputs, and lifecycle hooks
Angular Service
Build Angular services with dependency injection and HTTP client
Angular Forms
Build reactive forms with validation and custom validators
Angular RxJS
Use RxJS operators for async data flows in Angular
Angular NgRx
Set up NgRx state management with actions, reducers, and effects
Angular Testing
Write Angular unit tests with Jasmine and Karma
Angular Signals State Management
Use Angular Signals for reactive state without RxJS complexity
Angular RxJS Best Practices
Use RxJS operators correctly to avoid memory leaks and subscription bugs
Want a Angular skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.