docs(router): correct references to guard services (#50514)

PR Close #50514
This commit is contained in:
Arno Chauveau
2023-05-30 13:19:01 +02:00
committed by Dylan Hunn
parent 9750f59fd4
commit 8ce28dbafa
+5 -9
View File
@@ -349,7 +349,7 @@ The following route guards are available in Angular:
To use route guards, consider using [component-less routes](api/router/Route#componentless-routes) as this facilitates guarding child routes.
Create a service for your guard:
Create a file for your guard:
<code-example format="shell" language="shell">
@@ -357,28 +357,24 @@ ng generate guard your-guard
</code-example>
In your guard function, implement the guard you want to use.
The following example uses `canActivate` to guard the route.
In your guard file, add the guard functions you want to use.
The following example uses `canActivateFn` to guard the route.
<code-example header="guard (excerpt)">
export const yourGuard: CanActivateFn = (
export const yourGuardFunction: CanActivateFn = (
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot) => {
// your logic goes here
}
</code-example>
In your routing module, use the appropriate property in your `routes` configuration.
Here, `canActivate` tells the router to mediate navigation to this particular route.
<code-example header="Routing module (excerpt)">
{
path: '/your-path',
component: YourComponent,
canActivate: [yourGuard],
canActivate: [yourGuardFunction],
}
</code-example>