liveBook · Manning

mapToCanActivateChild

As explained in Pro Angular 16

mapToCanActivateChild is an Angular function that converts classes defining canActivateChild into functional child-route guards.

mapToCanActivateChild converts a class-based child-route guard into a value assigned to a route’s canActivateChild property. Angular calls the class’s canActivateChild method before activating any child route. section 26.2.2

Apply a class guard to child routes

Import mapToCanActivateChild and assign the generated guard to the parent route: canActivateChild: mapToCanActivateChild([TermsGuard]). The guard can receive ActivatedRouteSnapshot and RouterStateSnapshot objects, use dependency injection, and return a supported synchronous or asynchronous result. section 26.2.2

How Pro Angular 16 covers it

How deep it goes
Explains the mapping and invocation point, then demonstrates configuration and guard behavior without detailing the mapping internals.
Examples
Uses TermsGuard to prompt before category or product child routes and redirect to a sibling route when the user rejects navigation.
What it assumes
Assumes familiarity with Angular routing, child routes, injectable services, and guard result types.
What you can do after
Apply it via Angular Router to adapt an injectable class guard for a parent route’s canActivateChild configuration.
How it connects
Connects child route guards with canActivateChild, dependency injection, ActivatedRouteSnapshot, RouterStateSnapshot, and Router navigation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.