Method that gets executed when user navigates away from the component
that had defined the method. The user can prevent the navigation
by returning commands.prevent()
from the method or same value wrapped
in Promise
. This effectively means that the corresponding component
should be resolved by the router before the method can be executed.
If the router navigates to the same path twice in a row, and this results
in rendering the same component name (if the component is created
using component
property in the route object) or the same component instance
(if the component is created and returned inside action
property of the route object),
in the second time the method is not called. In case of navigating to a different path
but within the same route object, e.g. the path has parameter or wildcard,
and this results in rendering the same component instance, the method is called if available.
The WebComponent instance on which the callback has been invoked is available inside the callback through
the this
reference.
Return values:
commands.prevent()
result is returned (immediately or
as a Promise), the navigation is aborted and the outlet contents
is not updated.Arguments:
the RouterLocation
object
the commands object with the following methods:
Property | Description |
---|---|
commands.prevent() |
function that creates a special object that can be returned to abort the current |
navigation and fall back to the last one. If there is no existing one, an exception is thrown. |
the Router
instance
Web component route interface with onBeforeLeave callback.
Deprecated
Use WebComponentInterface.