Router Guards

Router Guards enable further decoupling and reuse of logic and greater control over the component lifecycle.

Here are the four major guards you will most likely use:

  1. CanActivate and CanActivateChild, used for checking auth access to a route
  2. CanDeactivate, used to ask permission before navigating away from a route
  3. Resolve, allows for pre-fetching of data from route parameters
  4. CanLoad, allows for custom logic to execute before loading feature module assets

Refer to the following sections for how to leverage CanActivate and CanLoad . Resolve guard will be covered in Chapter 10, Angular App Design and Recipes.

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.