Route Guard
noun
say it: “ROWT GARD” /raʊt ɡɑːrd/
A function that decides whether the router may go to a route, such as only for signed-in users.
What is Route Guard?
A route guard is a function the router runs before entering (or leaving) a route. It can block the navigation, for example sending logged-out users to the login page.
export const authGuard: CanActivateFn = () =>
inject(AuthService).isLoggedIn() || inject(Router).parseUrl('/login');
{ path: 'account', component: Account, canActivate: [authGuard] }
In a sentence
- “A route guard sends anyone who isn't signed in from /orders to the login page.”
Level: Journeyman · More Angular terms at this level
Updated