oguzhan18/angular-ecosystem-skills

angular-guards

ALWAYS use when working with Angular Route Guards, CanActivate, CanDeactivate, CanLoad, or route protection in Angular applications.

First seen Apr 2, 2026

Installation

$ npx skills add oguzhan18/angular-ecosystem-skills --skill angular-guards

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from oguzhan18/angular-ecosystem-skills · top by installs.

npx skills add oguzhan18/angular-ecosystem-skills

Browse all from oguzhan18/angular-ecosystem-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 7
License LICENSE
Default branch main
Open issues 0
Status Active

Skill metadata

Parsed from SKILL.md frontmatter.

Version21.0.0
More metadata
version
21.0.0
generated_by
oguzhancart
generated_at
2026-02-19

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,764 B
  • docs SUMMARY.md 154 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 182 installs

SKILL.md

Angular Route Guards

Version: Angular 21 (2025) Tags: Guards, Routing, Auth, CanActivate

References: Guards GuideCanActivate

API Changes

This section documents recent version-specific API changes.

  • NEW: Functional guards — Use CanActivateFn instead of class-based
  • NEW: CanMatch guard — Prevent lazy loading of unauthorized code
  • NEW: provideRouter with guards — Modern guard registration
  • DEPRECATED: Class-based guards — Migrate to functional

Best Practices

  • Create functional guard
export const authGuard: CanActivateFn = () => {
  const authService = inject(AuthService);
  const router = inject(Router);
  
  if (authService.isAuthenticated()) {
    return true;
  }
  return router.createUrlTree(['/login']);
};
  • Use CanActivate for route protection
const routes: Routes = [
  {
    path: 'dashboard',
    canActivate: [authGuard],
    component: DashboardComponent
  }
];
  • Use CanActivateChild for child routes
export const adminGuard: CanActivateChildFn = () => {
  const auth = inject(AuthService);
  return auth.isAdmin() || inject(Router).createUrlTree(['/unauthorized']);
};

const routes: Routes = [
  {
    path: 'admin',
    canActivateChild: [adminGuard],
    children: [...]
  }
];
  • Use CanMatch for lazy loading
const routes: Routes = [
  {
    path: 'admin',
    canMatch: [authGuard],
    loadComponent: () => import('./admin/admin.component')
  }
];
  • Use CanDeactivate for unsaved changes
export const canDeactivateGuard: CanDeactivateFn<CanComponentDeactivate> = (component) => {
  if (component.hasUnsavedChanges?.()) {
    return confirm('You have unsaved changes. Are you sure?');
  }
  return true;
};
  • Use withComponentInputBinding
export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes, withComponentInputBinding())
  ]
};
  • Use multiple guards
const routes: Routes = [
  {
    path: 'admin',
    canActivate: [authGuard, adminGuard],
    loadComponent: () => import('./admin/admin.component')
  }
];
  • Pass data to guards
const routes: Routes = [
  {
    path: 'user/:id',
    canActivate: [userGuard],
    data: { requiredRole: 'admin' }
  }
];

export const userGuard: CanActivateFn = (route, state) => {
  const requiredRole = route.data['requiredRole'];
  // Check role
};