CanActivateChildFn
Type Alias
The signature of a function used as a canActivateChild
guard on a Route
.
API
type CanActivateChildFn = ( childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot,) => MaybeAsync<GuardResult>
Description
The signature of a function used as a canActivateChild
guard on a Route
.
If all guards return true
, navigation continues. If any guard returns false
,
navigation is cancelled. If any guard returns a UrlTree
, the current navigation
is cancelled and a new navigation begins to the UrlTree
returned from the guard.
The following example implements a canActivate
function that checks whether the
current user has permission to activate the requested route.
const canActivateChildExample: CanActivateChildFn = ( route: ActivatedRouteSnapshot, state: RouterStateSnapshot,) => { return inject(PermissionsService).canActivate(inject(UserToken), route.params['id']);};bootstrapApplication(App, { providers: [ provideRouter([ { path: 'team/:id', component: TeamComponent, canActivateChild: [canActivateChildExample], children: [], }, ]), ],});
Jump to details