Interface BeforeEnterObserver

Web component route interface with onBeforeEnter callback.

Use WebComponentInterface.

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

Properties

Properties

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

Type declaration

    • (location, commands, router): MaybePromise<void | PreventResult | RedirectResult>
    • Method that gets executed before the outlet contents is updated with the new element. The user can prevent the navigation by returning commands.prevent() from the method or same value wrapped in Promise. 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.
      • if the commands.redirect(path) result is returned (immediately or as a Promise), Vaadin Router ends navigation to the current path, and starts a new navigation cycle to the new path.
      • 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.redirect(path) function that creates a redirect data for the path specified, to use as a return
        value from the callback.
        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.
        commands.redirectResult(path) function that creates a redirect data for the path specified, to use as a return
        value from the callback.
        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 | RedirectResult>