Interface BeforeLeaveObserver

Web component route interface with onBeforeLeave callback.

Use WebComponentInterface.

interface BeforeLeaveObserver {
    onBeforeLeave: ((location: RouterLocation<EmptyObject, EmptyObject>, commands: Commands, router: Router<EmptyObject, EmptyObject>) => MaybePromise<void | PreventResult>);
}

Properties

Properties

onBeforeLeave: ((location: RouterLocation<EmptyObject, EmptyObject>, commands: Commands, router: Router<EmptyObject, EmptyObject>) => MaybePromise<void | PreventResult>)

Type declaration

    • (location, commands, router): MaybePromise<void | PreventResult>
    • 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:

      • if the commands.prevent() result is returned (immediately or as a Promise), the navigation is aborted and the outlet contents is not updated.
      • any other return value is ignored and Vaadin Router proceeds with the navigation.

      Arguments:

      Parameters

      • location: RouterLocation<EmptyObject, EmptyObject>

        the RouterLocation object

      • commands: Commands

        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.
      • router: Router<EmptyObject, EmptyObject>

        the Router instance

      Returns MaybePromise<void | PreventResult>