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
      routeTargetChain - the route terget chain that will be used, not null
      location - the new location, 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.
      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.
      Parameters:
      statusCode - the http status code
    • getRerouteTarget

      public Optional<NavigationHandler> getRerouteTarget()
      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

      public void rerouteTo(NavigationHandler rerouteTarget)
      Reroutes the navigation to use the provided navigation handler instead of the currently used handler.

      This function doesn't change the browser URL.

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

      public void rerouteTo(NavigationState rerouteTargetState)
      Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.

      This function doesn't change the browser URL.

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