Package com.vaadin.flow.component.page
Class History
- java.lang.Object
-
- com.vaadin.flow.component.page.History
-
- All Implemented Interfaces:
Serializable
public class History extends Object implements Serializable
Representswindow.historyin 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHistory.HistoryStateChangeEventEvent fired when the history state has changed.static interfaceHistory.HistoryStateChangeHandlerHandles location change events.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidback()Navigates back.voidforward()Navigates forward.History.HistoryStateChangeHandlergetHistoryStateChangeHandler()Gets the handler that is notified history state has changed.UIgetUI()Gets the UI that this instance belongs to.voidgo(int steps)Navigates a number of steps forward or backward in the history.voidpushState(elemental.json.JsonValue state, Location location)Invokeshistory.pushStatein the browser with the given parameters.voidpushState(elemental.json.JsonValue state, String location)Invokeshistory.pushStatein the browser with the given parameters.voidreplaceState(elemental.json.JsonValue state, Location location)Invokeshistory.replaceStatein the browser with the given parameters.voidreplaceState(elemental.json.JsonValue state, String location)Invokeshistory.replaceStatein the browser with the given parameters.voidsetHistoryStateChangeHandler(History.HistoryStateChangeHandler historyStateChangeHandler)Sets a handler that will be notified when the history state has changed.
-
-
-
Constructor Detail
-
History
public History(UI ui)
Creates a history API endpoint for the given UI.- Parameters:
ui- the ui, not null
-
-
Method Detail
-
getUI
public UI getUI()
Gets the UI that this instance belongs to.- Returns:
- the ui, not null
-
pushState
public void pushState(elemental.json.JsonValue state, String location)Invokeshistory.pushStatein the browser with the given parameters. This is a shorthand method forpushState(JsonValue, Location), creatingLocationfrom the string provided.- Parameters:
state- the JSON state to push to the history stack, ornullto only change the locationlocation- the new location to set in the browser, ornullto only change the JSON state
-
pushState
public void pushState(elemental.json.JsonValue state, Location location)Invokeshistory.pushStatein the browser with the given parameters.- Parameters:
state- the JSON state to push to the history stack, ornullto only change the locationlocation- the new location to set in the browser, ornullto only change the JSON state
-
replaceState
public void replaceState(elemental.json.JsonValue state, String location)Invokeshistory.replaceStatein the browser with the given parameters. This is a shorthand method forreplaceState(JsonValue, Location), creatingLocationfrom the string provided.- Parameters:
state- the JSON state to push to the history stack, ornullto only change the locationlocation- the new location to set in the browser, ornullto only change the JSON state
-
replaceState
public void replaceState(elemental.json.JsonValue state, Location location)Invokeshistory.replaceStatein the browser with the given parameters.- Parameters:
state- the JSON state to push to the history stack, ornullto only change the locationlocation- the new location to set in the browser, ornullto only change the JSON state
-
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
popstateevent 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, ornullto remove the current handler- See Also:
History.HistoryStateChangeEvent
-
getHistoryStateChangeHandler
public History.HistoryStateChangeHandler getHistoryStateChangeHandler()
Gets the handler that is notified history state has changed.- Returns:
- the history state handler, or
nullif no handler is set - See Also:
History.HistoryStateChangeEvent
-
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.HistoryStateChangeEventto 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.HistoryStateChangeEventto 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.HistoryStateChangeEventto 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.0causes the current page to be reloaded
-
-