/frontend-angular:angular-routingfrom frontend-angular
Angular Router configuration including lazy loading, route guards, nested routes, route params, navigation, resolvers, preloading strategies, and functional guards.
Ships in frontend-angular. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use provideRouter in bootstrapApplication (standalone apps) or RouterModule.forRoot in an NgModule app.
// main.ts — standalone bootstrap
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, withPreloading, PreloadAllModules } from '@angular/router';
import { AppComponent } from './app/app.component';
import { routes } from './app/app.routes';
bootstrapApplication(AppComponent, {
providers: [
provideRouter(routes, withPreloading(PreloadAllModules)),
],
});
// app.routes.ts
import { Routes } from '@angular/router';
export const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', loadComponent: () => import('./home/home.component').then(m => m.HomeComponent) },
{
path: 'admin',
canActivate: [authGuard],
loadChildren: () => import('./admin/admin.routes').then(m => m.ADMIN_ROUTES),
},
{ path: '**', loadComponent: () => import('./not-found/not-found.component').then(m => m.NotFoundComponent) },
];
{
path: 'profile',
loadComponent: () =>
import('./profile/profile.component').then(m => m.ProfileComponent),
}
// app.routes.ts
{
path: 'products',
loadChildren: () =>
import('./products/products.routes').then(m => m.PRODUCTS_ROUTES),
}
// products/products.routes.ts
export const PRODUCTS_ROUTES: Routes = [
{ path: '', component: ProductListComponent },
{ path: ':id', component: ProductDetailComponent },
];
Lazy load feature modules/routes to keep the initial bundle small. Every major feature should have its own lazy-loaded route set.
Use functional guards instead of class-based guards for simpler, tree-shakable code.
// auth.guard.ts
import { inject } from '@angular/core';
import { CanActivateFn, Router } from '@angular/router';
import { AuthService } from './auth.service';
export const authGuard: CanActivateFn = (route, state) => {
const auth = inject(AuthService);
const router = inject(Router);
if (auth.isAuthenticated()) {
return true;
}
return router.createUrlTree(['/login'], { queryParams: { returnUrl: state.url } });
};
export const unsavedChangesGuard: CanDeactivateFn<{ hasUnsavedChanges: () => boolean }> =
(component) => {
if (component.hasUnsavedChanges()) {
return confirm('You have unsaved changes. Leave anyway?');
}
return true;
};
| Guard | Purpose |
|---|---|
canActivate | Block route activation |
canActivateChild | Block child route activation |
canDeactivate | Prevent navigation away |
canMatch | Prevent route matching entirely |
resolve | Pre-fetch data before component renders |
Apply guards on the route config:
{
path: 'settings',
component: SettingsComponent,
canActivate: [authGuard, roleGuard('admin')],
canDeactivate: [unsavedChangesGuard],
resolve: { settings: settingsResolver },
}
Use nested route configs with <router-outlet> in the parent component.
// admin/admin.routes.ts
export const ADMIN_ROUTES: Routes = [
{
path: '',
component: AdminLayoutComponent, // contains <router-outlet>
children: [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: AdminDashboardComponent },
{ path: 'users', component: UserManagementComponent },
{ path: 'users/:id', component: UserDetailComponent },
],
},
];
<!-- admin-layout.component.html -->
<app-admin-sidebar />
<main>
<router-outlet />
</main>
Primary outlet:
<router-outlet />
Named outlets (auxiliary routes):
<router-outlet name="sidebar" />
// Navigate to named outlet
this.router.navigate([{ outlets: { sidebar: ['help'] } }]);
{ path: 'users/:id', component: UserDetailComponent }
Read in component using inject(ActivatedRoute):
@Component({ standalone: true, ... })
export class UserDetailComponent implements OnInit {
private route = inject(ActivatedRoute);
private userService = inject(UserService);
userId = toSignal(
this.route.paramMap.pipe(map(params => params.get('id')!))
);
user = toSignal(
this.route.paramMap.pipe(
switchMap(params => this.userService.getUser(params.get('id')!))
)
);
}
// Read query params
queryParams = toSignal(this.route.queryParamMap);
search = computed(() => this.queryParams()?.get('search') ?? '');
// Navigate with query params
this.router.navigate(['/users'], { queryParams: { search: 'john', page: 1 } });
private router = inject(Router);
// Navigate by path
this.router.navigate(['/users', userId]);
// Navigate relative to current route
this.router.navigate(['../edit'], { relativeTo: this.route });
// Navigate with extras
this.router.navigate(['/dashboard'], {
queryParams: { tab: 'overview' },
fragment: 'summary',
replaceUrl: true, // don't add to browser history
});
<!-- Absolute path -->
<a routerLink="/users">All Users</a>
<!-- With params -->
<a [routerLink]="['/users', user.id]">{{ user.name }}</a>
<!-- With query params -->
<a [routerLink]="['/search']" [queryParams]="{ q: searchTerm }">Search</a>
<!-- Active link styling -->
<a routerLink="/home" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }">Home</a>
{
path: 'admin',
component: AdminComponent,
data: { title: 'Admin Panel', breadcrumb: 'Admin' },
}
Read in component:
title = toSignal(this.route.data.pipe(map(d => d['title'])));
// user.resolver.ts
import { inject } from '@angular/core';
import { ResolveFn } from '@angular/router';
import { UserService } from './user.service';
import { User } from './user.model';
export const userResolver: ResolveFn<User> = (route) => {
return inject(UserService).getUser(route.paramMap.get('id')!);
};
// Route config
{
path: 'users/:id',
component: UserDetailComponent,
resolve: { user: userResolver },
}
// Component — resolved data is available immediately
user = toSignal(this.route.data.pipe(map(d => d['user'] as User)));
Resolvers pre-fetch data before the component renders, avoiding loading states for critical data.
Preload all lazy modules after initial load:
provideRouter(routes, withPreloading(PreloadAllModules))
Preload only routes with a preload: true data property:
@Injectable({ providedIn: 'root' })
export class SelectivePreloadingStrategy implements PreloadingStrategy {
preload(route: Route, load: () => Observable<any>): Observable<any> {
return route.data?.['preload'] ? load() : of(null);
}
}
// Usage
{ path: 'dashboard', loadChildren: ..., data: { preload: true } }
Register the strategy:
provideRouter(routes, withPreloading(SelectivePreloadingStrategy))
provideRouter(
routes,
withPreloading(PreloadAllModules),
withComponentInputBinding(), // bind route params to component inputs
withViewTransitions(), // smooth page transitions
withRouterConfig({
paramsInheritanceStrategy: 'always', // child routes inherit parent params
onSameUrlNavigation: 'reload',
}),
)
When withComponentInputBinding() is enabled, route params, query params, and resolved data are automatically bound to component input() signals:
@Component({ standalone: true, ... })
export class UserDetailComponent {
id = input<string>(); // bound from :id path param
tab = input<string>('info'); // bound from ?tab= query param
user = input<User>(); // bound from resolve: { user: userResolver }
}
This eliminates the need to manually inject ActivatedRoute in many cases.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub gagandeepp/software-agent-teams --plugin frontend-angularOther plugins' skills for the same job
7 skills in this plugin
/angular-componentsAngular component patterns including standalone components, signals, directives, pipes, content projection, view queries, lifecycle hooks, and change detection strategies./angular-data-fetchingAngular data fetching patterns including HttpClient, interceptors, resolvers, RxJS operators, caching, loading/error state management, and SSR TransferState./angular-project-structureAngular workspace structure including Angular CLI, Nx monorepos, feature module organization, shared/core conventions, lazy-loaded routes, library projects, environment config, and barrel exports.