How to Implement Functional Guards
const authGuard: CanActivateFn = (route, state) => {
const authService = inject(AuthService);
return authService.isLoggedIn() ? true : inject(Router).createUrlTree(['/login']);
};
Learn how to refactor your legacy class-based Angular router guards to the modern functional router guard pattern.
const authGuard: CanActivateFn = (route, state) => {
const authService = inject(AuthService);
return authService.isLoggedIn() ? true : inject(Router).createUrlTree(['/login']);
};