Migrating to Functional Router Guards in Angular
Migrating to Functional Router Guards in Angular

Migrating to Functional Router Guards in Angular

Saptarshi Chakraborty

Saptarshi Chakraborty

August 17, 2026 • 1 min read

Learn how to refactor your legacy class-based Angular router guards to the modern functional router guard pattern.

Table of Contents

Class-based router guards are officially deprecated in favor of simple, functional guards. Functional guards reduce boilerplates and can be written directly inline. For code modernization consulting, hire an Angular consultant India to audit your architecture.

How to Implement Functional Guards

Functional guards are plain functions of type `CanActivateFn`. You can inject services directly inside the function using the `inject` utility:

const authGuard: CanActivateFn = (route, state) => {
  const authService = inject(AuthService);
  return authService.isLoggedIn() ? true : inject(Router).createUrlTree(['/login']);
};

Injecting Route Parameters

You can inspect route parameters directly within the function parameter `route.params`. This allows functional guards to run permission checks dynamically before navigating to page modules.

Topics