Class LocationChangeEvent

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

public class LocationChangeEvent extends EventObject
Event created when the location changes by any of the reasons defined at NavigationTrigger.
Since:
1.0
See Also:
  • Constructor Details

    • LocationChangeEvent

      public LocationChangeEvent(Router router, UI ui, NavigationTrigger trigger, Location location, List<HasElement> routeTargetChain)
      Creates a new location change event.
      Parameters:
      router - the router that triggered the change, not null
      ui - the UI in which the view is used, not null
      trigger - the type of user action that triggered this location change, not null
      location - the new location, not null
      routeTargetChain - the route terget chain that will be used, not null
  • Method Details

    • getLocation

      public Location getLocation()
      Gets the new location.
      Returns:
      the new location, not null
    • getRouteTargetChain

      public List<HasElement> getRouteTargetChain()
      Gets the chain of route targets that will be nested inside the UI, starting from the most deeply nested component.
      Returns:
      the view chain, not null
    • getUI

      public UI getUI()
      Gets the UI in which the view is shown.
      Returns:
      the UI, not null
    • getTrigger

      public NavigationTrigger getTrigger()
      Gets the type of user action that triggered this location change.
      Returns:
      the type of user action that triggered this location change, not null
    • getQueryParameters

      public Map<String,List<String>> getQueryParameters()
      Gets the query parameters used for navigation. If only the first value of parameter list is important, please use getQueryParameter(String)
      Returns:
      the query parameters, not null
    • getQueryParameter

      public Optional<String> getQueryParameter(String parameterName)
      Gets first parameter that corresponds to specified parameterName. If there are multiple parameters corresponding to the same parameterName, the first one will be returned. To access all parameters, use getQueryParameters() method.
      Parameters:
      parameterName - the name of a parameter to get
      Returns:
      first corresponding query parameter or Optional.empty(), if no parameters found for parameterName specified
    • getSource

      public Router getSource()
      Overrides:
      getSource in class EventObject
    • getStatusCode

      public int getStatusCode()
      Gets the HTTP status code that will be returned for the client if this location change is an initial rendering request.

      The router reads this value right after the route target has been shown and before the after-navigation events are fired, so a value set from an AfterNavigationEvent is never returned to the client.

      Returns:
      the http status code
    • setStatusCode

      public void setStatusCode(int statusCode)
      Sets the HTTP status code that will be returned for the client if this location change is an initial rendering request.

      Only effective while the navigation is still being resolved, i.e. from HasErrorParameter.setErrorParameter(BeforeEnterEvent, ErrorParameter). The router has already read the status code by the time the after-navigation events are fired, so a value set from an AfterNavigationEvent never reaches the client. It is still returned by getStatusCode(), and setting it that late logs a warning.

      Parameters:
      statusCode - the http status code
    • getRerouteTarget

      @Deprecated(since="25.4", forRemoval=true) public Optional<NavigationHandler> getRerouteTarget()
      Deprecated, for removal: This API element is subject to removal in a future version.
      the router never reads this value; use BeforeEvent.getRerouteTarget() instead
      Gets the reroute target to use if the user should be rerouted to some other view.
      Returns:
      and optional navigation handler, or an empty optional if no reroute target has been set
    • rerouteTo

      @Deprecated(since="25.4", forRemoval=true) public void rerouteTo(NavigationHandler rerouteTarget)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Reroutes the navigation to use the provided navigation handler instead of the currently used handler.

      This method has no effect on the navigation: the router does not read the reroute target of a LocationChangeEvent, and the only event handing one out, AfterNavigationEvent, fires when the navigation can no longer be changed. The target is still returned by getRerouteTarget(), and setting it logs a warning.

      Parameters:
      rerouteTarget - the navigation handler to use, or null to clear a previously set reroute target
    • rerouteTo

      @Deprecated(since="25.4", forRemoval=true) public void rerouteTo(NavigationState rerouteTargetState)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.

      This method has no effect on the navigation, see rerouteTo(NavigationHandler).

      Parameters:
      rerouteTargetState - the target navigation state of the rerouting, not null