Package com.vaadin.flow.component.page
Class History
java.lang.Object
com.vaadin.flow.component.page.History
- All Implemented Interfaces:
Serializable
Represents
window.history
in the browser. See e.g.
documentation on MDN for detailed information on how the API works in the
browser.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Event fired when the history state has changed.static interface
Handles location change events. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
back()
Navigates back.void
forward()
Navigates forward.Gets the handler that is notified history state has changed.getUI()
Gets the UI that this instance belongs to.void
go
(int steps) Navigates a number of steps forward or backward in the history.void
Invokeshistory.pushState
in the browser with the given parameters.void
Invokeshistory.pushState
in the browser with the given parameters.void
Invokeshistory.pushState
in the browser with the given parameters.void
Invokeshistory.pushState
in the browser with the given parameters.void
replaceState
(elemental.json.JsonValue state, Location location) Invokeshistory.replaceState
in the browser with the given parameters.void
replaceState
(elemental.json.JsonValue state, Location location, boolean callback) Invokeshistory.replaceState
in the browser with the given parameters.void
replaceState
(elemental.json.JsonValue state, String location) Invokeshistory.replaceState
in the browser with the given parameters.void
replaceState
(elemental.json.JsonValue state, String location, boolean callback) Invokeshistory.replaceState
in the browser with the given parameters.void
setHistoryStateChangeHandler
(History.HistoryStateChangeHandler historyStateChangeHandler) Sets a handler that will be notified when the history state has changed.
-
Constructor Details
-
History
Creates a history API endpoint for the given UI.- Parameters:
ui
- the ui, not null
-
-
Method Details
-
getUI
Gets the UI that this instance belongs to.- Returns:
- the ui, not null
-
pushState
Invokeshistory.pushState
in the browser with the given parameters. This is a shorthand method forpushState(JsonValue, Location)
, creatingLocation
from the string provided.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON state
-
pushState
Invokeshistory.pushState
in the browser with the given parameters. This is a shorthand method forpushState(JsonValue, Location, boolean)
, creatingLocation
from the string provided.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON statecallback
-true
if the change should make a return call to the server
-
pushState
Invokeshistory.pushState
in the browser with the given parameters. Does not make a callback to the server by default.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON state
-
pushState
Invokeshistory.pushState
in the browser with the given parameters.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON statecallback
-true
if the change should make a return call to the server
-
replaceState
Invokeshistory.replaceState
in the browser with the given parameters. This is a shorthand method forreplaceState(JsonValue, Location)
, creatingLocation
from the string provided.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON state
-
replaceState
Invokeshistory.replaceState
in the browser with the given parameters. This is a shorthand method forreplaceState(JsonValue, Location, boolean)
, creatingLocation
from the string provided.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON statecallback
-true
if the change should make a return call to the server
-
replaceState
Invokeshistory.replaceState
in the browser with the given parameters. Does not make a callback to the server by default.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON state
-
replaceState
Invokeshistory.replaceState
in the browser with the given parameters.- Parameters:
state
- the JSON state to push to the history stack, ornull
to only change the locationlocation
- the new location to set in the browser, ornull
to only change the JSON statecallback
-true
if the change should make a return call to the server
-
setHistoryStateChangeHandler
public void setHistoryStateChangeHandler(History.HistoryStateChangeHandler historyStateChangeHandler) Sets a handler that will be notified when the history state has changed.History state changes are triggered when a
popstate
event is fired in the browser or when the user has navigated using a router link. There can only be one handler at a time.- Parameters:
historyStateChangeHandler
- the handler to set, ornull
to remove the current handler- See Also:
-
getHistoryStateChangeHandler
Gets the handler that is notified history state has changed.- Returns:
- the history state handler, or
null
if no handler is set - See Also:
-
back
public void back()Navigates back. This has the same effect as if the user would press the back button in the browser. This causes aHistory.HistoryStateChangeEvent
to be fired asynchronously if the conditions described in the onpopstate documentation are met. -
forward
public void forward()Navigates forward. This has the same effect as if the user would press the forward button in the browser. This causes aHistory.HistoryStateChangeEvent
to be fired asynchronously if the conditions described in the onpopstate documentation are met. -
go
public void go(int steps) Navigates a number of steps forward or backward in the history. This has the same effect as if the user would press the forward button in the browser. This causes aHistory.HistoryStateChangeEvent
to be fired asynchronously if the conditions described in the onpopstate documentation are met.- Parameters:
steps
- the number of steps to navigate, positive numbers navigate forward, negative numbers backward.0
causes the current page to be reloaded
-