NavigationBehaviorOptions
Options that modify the Router
navigation strategy.
Supply an object containing any of these properties to a Router
navigation function to
control how the navigation should be handled.
interface NavigationBehaviorOptions {}
skipLocationChange
boolean | undefined
When true, navigates without pushing a new state into history.
// Navigate silently to /viewthis.router.navigate(['/view'], { skipLocationChange: true });
replaceUrl
boolean | undefined
When true, navigates while replacing the current state in history.
// Navigate to /viewthis.router.navigate(['/view'], { replaceUrl: true });
state
{ [k: string]: any; } | undefined
Developer-defined state that can be passed to any navigation.
Access this value through the Navigation.extras
object
returned from the Router.getCurrentNavigation()
method while a navigation is executing.
After a navigation completes, the router writes an object containing this
value together with a navigationId
to history.state
.
The value is written when location.go()
or location.replaceState()
is called before activating this route.
Note that history.state
does not pass an object equality test because
the router adds the navigationId
on each navigation.
info
unknown
Use this to convey transient information about this particular navigation, such as how it
happened. In this way, it's different from the persisted value state
that will be set to
history.state
. This object is assigned directly to the Router's current Navigation
(it is not copied or cloned), so it should be mutated with caution.
One example of how this might be used is to trigger different single-page navigation animations depending on how a certain route was reached. For example, consider a photo gallery app, where you can reach the same photo URL and state via various routes:
- Clicking on it in a gallery view
- Clicking
- "next" or "previous" when viewing another photo in the album
- Etc.
Each of these wants a different animation at navigate time. This information doesn't make sense to store in the persistent URL or history entry state, but it's still important to communicate from the rest of the application, into the router.
This information could be used in coordination with the View Transitions feature and the
onViewTransitionCreated
callback. The information might be used in the callback to set
classes on the document in order to control the transition animations and remove the classes
when the transition has finished animating.