Angular › Router Guards & Resolvers
How would you combine multiple route guards together to enforce both authentication and a specific user role?
AdvancedAnswer
You list several guard functions in the canActivate array for a route, and Angular runs them in order, only allowing navigation to proceed if every single guard returns true, letting you compose simple, focused guards together rather than writing one large guard handling everything at once.
export const adminGuard: CanActivateFn = () => {
const authService = inject(AuthService);
return authService.currentUser()?.role === 'admin';
};
{ path: 'admin', component: AdminPanelComponent, canActivate: [authGuard, adminGuard] }Real-world example An admin panel requires both a general authGuard confirming the user is logged in at all, and a separate adminGuard confirming their specific role is admin, composing two small, focused guards together on the same route.