liveBook · Manning

canActivateChild method

As explained in Pro Angular 16

The canActivateChild method is a guard method that determines whether a child route may be activated.

The canActivateChild method is a class-based route-guard method that runs before Angular activates any child route beneath a guarded parent. It receives ActivatedRouteSnapshot and RouterStateSnapshot objects and can use dependency injection, which makes it practical for checks involving services. section 26.2.2

Use the method by following this configuration pattern:

  • Define a guard class containing canActivateChild. section 26.2.2
  • Return the appropriate guard result; Angular activates the child when the result permits navigation. section 26.2.2

Guarding product child routes

A TermsGuard can protect a parent route containing products and categories children. Its canActivateChild method prompts the user for the categories route, resolves true for Yes, and rejects navigation for No; it can also use Router to redirect.

How Pro Angular 16 covers it

How deep it goes
Explains class-based configuration and execution, but omits the complete method implementation details.
Examples
Uses products and categories child routes, a TermsGuard, a user prompt, and Router-based redirection.
What it assumes
Assumes familiarity with Angular routes and guards while refreshing parent-child route protection and guard registration.
What you can do after
Apply it via Angular Router to protect multiple child routes with one injectable guard class.
How it connects
Connects child route guards with dependency injection, route configuration, Router, ActivatedRouteSnapshot, and RouterStateSnapshot.

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.