Angular’s “CanActivate” interface is deprecated. How to replace it?

The trick is to rely on inject() for the injection of the instances you need : export const canActivate: CanActivateFn = ( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ) => { const authService = inject(AuthenticationService); const router = inject(Router); return authService.checkLogin().pipe( map(() => true), catchError(() => { router.navigate([‘route-to-fallback-page’]); return of(false); }) ); }; export const canActivateChild: CanActivateChildFn … Read more