com.vaadin.flow.router.
Class LocationChangeEvent
- java.lang.Object
-
- java.util.EventObject
-
- com.vaadin.flow.router.LocationChangeEvent
-
All Implemented Interfaces:
public class LocationChangeEvent extends EventObject
Event created when the location changes by any of the reasons defined at
NavigationTrigger
.Since:
1.0
See Also:
-
-
Field Summary
-
Fields inherited from class java.util.EventObject
source
-
-
Constructor Summary
Constructors Constructor and Description LocationChangeEvent(Router router, UI ui, NavigationTrigger trigger, Location location, List<HasElement> routeTargetChain)
Creates a new location change event.
-
Method Summary
All Methods Modifier and Type Method and Description Location
getLocation()
Gets the new location.
Optional<String>
getQueryParameter(String parameterName)
Gets first parameter that corresponds to specified
parameterName
.Map<String,List<String>>
getQueryParameters()
Gets the query parameters used for navigation.
Optional<NavigationHandler>
getRerouteTarget()
Gets the reroute target to use if the user should be rerouted to some other view.
List<HasElement>
getRouteTargetChain()
Gets the chain of route targets that will be nested inside the UI, starting from the most deeply nested component.
Router
getSource()
int
getStatusCode()
Gets the HTTP status code that will be returned for the client if this location change is an initial rendering request.
NavigationTrigger
getTrigger()
Gets the type of user action that triggered this location change.
UI
getUI()
Gets the UI in which the view is shown.
void
rerouteTo(NavigationHandler rerouteTarget)
Reroutes the navigation to use the provided navigation handler instead of the currently used handler.
void
rerouteTo(NavigationState rerouteTargetState)
Reroutes the navigation to show the given component instead of the component that is currently about to be displayed.
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.
-
Methods inherited from class java.util.EventObject
toString
-
-
-
-
Constructor Detail
-
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, notnull
ui
- the UI in which the view is used, notnull
trigger
- the type of user action that triggered this location change, notnull
routeTargetChain
- the route terget chain that will be used, notnull
location
- the new location, notnull
-
-
Method Detail
-
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 sameparameterName
, the first one will be returned. To access all parameters, usegetQueryParameters()
method.Parameters:
parameterName
- the name of a parameter to getReturns:
first corresponding query parameter or
Optional.empty()
, if no parameters found forparameterName
specified
-
getSource
public Router getSource()
Overrides:
getSource
in classEventObject
-
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.
Parameters:
rerouteTarget
- the navigation handler to use, ornull
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.
Parameters:
rerouteTargetState
- the target navigation state of the rerouting, notnull
-
-