liveBook · Manning

RouterStateSnapshot

As explained in Pro Angular 16

RouterStateSnapshot is an Angular route-information object that represents the router state for a navigation, including its URL.

RouterStateSnapshot represents the router state associated with a navigation, including the navigation URL. Angular supplies it to route guards alongside ActivatedRouteSnapshot. section 26.2.2

A guard can inspect the current route snapshot while deciding whether navigation should proceed. The snapshot is distinct from input properties, which cannot receive routing parameters in guards. section 26.2.2

Using the snapshot in a route guard

A TermsGuard receives ActivatedRouteSnapshot and RouterStateSnapshot in canActivate. It checks route.params["mode"] to protect create navigation, then returns true immediately or waits for a Promise<boolean> representing the user's response. section 26.2.2

How Pro Angular 16 covers it

How deep it goes
Defines the guard argument and navigation context, but defers the snapshot's internal structure and lifecycle.
Examples
Uses TermsGuard to inspect a create mode and request confirmation before activating a route.
What it assumes
Assumes familiarity with Angular routing and guards while refreshing snapshot access to route information.
What you can do after
Apply it via Angular route guards by accepting the snapshot in canActivate, canActivateChild, or canDeactivate methods.
How it connects
Connects route guards, ActivatedRouteSnapshot, resolvers, canActivate, canActivateChild, and canDeactivate.

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.