Beta
Add a blocker that can prevent navigation away from the current page, for example when there is some unsaved data that would otherwise be discarded.
If the blocker function returns true navigation is blocked. If it returns false navigation will proceed as normal, if not blocked by other blockers.
To later on resume navigation that was blocked, you can call the supplied Transition.retry method.
Blockers are not guaranteed to be executed upon a navigation event. Blockers will be executed until either all returns false or up until one of them returns true.
navigator.addBlocker(myBlocker);
function myBlocker(transition) {
showConfirmDialog().then((shouldNavigate) => {
if (shouldNavigate) {
navigator.removeBlocker(myBlocker);
transition.retry()
}
});
return true;
}
function to be called before navigation
Navigate to a new location
navigate - When the location has been changed the EventDispatcher will emit a NavigationEvent
path to the location
Optional
query: Record<string, unknown>query string parameters to append to the URL
Navigate to a new location or update the current location with new data
By default, it is automatically decided whether to replace the current history entry or push a new one. If no new path is provided, or if it resolves to an unchanged path of the URL (not including the query string or fragment), the current history entry will be updated with the provided location data.
You can also set location.method
to push or replace instead.
When pushing a new entry, location.state
defaults to null
.
When replacing, state will only be changed if a new value is provided.
navigate - When the location has been changed the EventDispatcher will emit a NavigationEvent
a new location or parts of the location to replace
The Navigator service lets you navigate to a new location within the application, or update the current location with new data. A location is defined by a path and optional data.
When navigating to a new location, a new entry will be pushed to the history stack in the browser and the EventDispatcher will emit a NavigationEvent.
New locations can be registered using the RouteRegistry service
Example