Class NavigationStartedEvent

java.lang.Object
java.util.EventObject
com.vaadin.flow.router.NavigationStartedEvent
All Implemented Interfaces:
Serializable

public class NavigationStartedEvent extends EventObject
Event fired through the service event bus when the server starts handling a navigation for a UI, before any BeforeLeaveEvent or BeforeEnterEvent listener runs.

The event is meant for monitoring tools that time navigations or count them per route. Every started event is followed by exactly one NavigationEndedEvent for the same navigation, fired on the same thread when the handling has finished, whatever the outcome. A listener can therefore keep timing state in a ThreadLocal. Both events are fired on the request thread while the session is locked.

Only the outermost navigation is reported. The navigations that Flow runs while handling it are part of it and fire no events of their own: a forward or reroute, the redirect that adds or removes a trailing slash, and the rendering of an error view. The ended event tells which view was shown in the end.

Resuming a postponed navigation with BeforeLeaveEvent.ContinueNavigationAction.proceed() is reported as a navigation of its own. Showing a PreserveOnRefresh view once the browser has sent its window name fires no events, since it continues a navigation that has already been reported.

The location and trigger are the ones requested, as they are before any forward or reroute.

Since:
25.4
See Also:
  • Constructor Details

    • NavigationStartedEvent

      public NavigationStartedEvent(UI ui, Location location, NavigationTrigger trigger)
      Creates a new event.
      Parameters:
      ui - the UI that navigates, not null
      location - the requested location, not null
      trigger - the action that triggered the navigation, not null
  • Method Details

    • getUI

      public UI getUI()
      Gets the UI that navigates.
      Returns:
      the UI, never null
    • getLocation

      public Location getLocation()
      Gets the location that was requested, before any forward or reroute.
      Returns:
      the requested location, never null
    • getTrigger

      public NavigationTrigger getTrigger()
      Gets the action that triggered the navigation, such as a page load, a click on a router link or a call to UI.navigate(String).
      Returns:
      the navigation trigger, never null