public class History extends Object implements Serializable
window.history
in the browser. See e.g.
documentation on MDN for detailed information on how the API works in the
browser.Modifier and Type | Class and Description |
---|---|
static class |
History.HistoryStateChangeEvent
Event fired when the history state has changed.
|
static interface |
History.HistoryStateChangeHandler
Handles location change events.
|
Constructor and Description |
---|
History(UI ui)
Creates a history API endpoint for the given UI.
|
Modifier and Type | Method and Description |
---|---|
void |
back()
Navigates back.
|
void |
forward()
Navigates forward.
|
History.HistoryStateChangeHandler |
getHistoryStateChangeHandler()
Gets the handler that is notified history state has changed.
|
UI |
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 |
pushState(elemental.json.JsonValue state,
Location location)
Invokes
window.history.pushState in the browser with the given
parameters. |
void |
pushState(elemental.json.JsonValue state,
String location)
Invokes
window.history.pushState in the browser with the given
parameters. |
void |
replaceState(elemental.json.JsonValue state,
Location location)
Invokes
window.history.replaceState in the browser with the given
parameters. |
void |
replaceState(elemental.json.JsonValue state,
String location)
Invokes
window.history.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.
|
public History(UI ui)
ui
- the ui, not nullpublic UI getUI()
public void pushState(elemental.json.JsonValue state, String location)
window.history.pushState
in the browser with the given
parameters. This is a shorthand method for
pushState(JsonValue, Location)
, creating Location
from the string provided.state
- the JSON state to push to the history stack, or
null
to only change the locationlocation
- the new location to set in the browser, or null
to only change the JSON statepublic void pushState(elemental.json.JsonValue state, Location location)
window.history.pushState
in the browser with the given
parameters.state
- the JSON state to push to the history stack, or
null
to only change the locationlocation
- the new location to set in the browser, or null
to only change the JSON statepublic void replaceState(elemental.json.JsonValue state, String location)
window.history.replaceState
in the browser with the given
parameters. This is a shorthand method for
replaceState(JsonValue, Location)
, creating
Location
from the string provided.state
- the JSON state to push to the history stack, or
null
to only change the locationlocation
- the new location to set in the browser, or null
to only change the JSON statepublic void replaceState(elemental.json.JsonValue state, Location location)
window.history.replaceState
in the browser with the given
parameters.state
- the JSON state to push to the history stack, or
null
to only change the locationlocation
- the new location to set in the browser, or null
to only change the JSON statepublic void setHistoryStateChangeHandler(History.HistoryStateChangeHandler historyStateChangeHandler)
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.
historyStateChangeHandler
- the handler to set, or null
to remove the current
handlerHistory.HistoryStateChangeEvent
public History.HistoryStateChangeHandler getHistoryStateChangeHandler()
null
if no handler is
setHistory.HistoryStateChangeEvent
public void back()
History.HistoryStateChangeEvent
to be fired asynchronously if the conditions described in the
onpopstate documentation are met.public void forward()
History.HistoryStateChangeEvent
to be fired asynchronously if the
conditions described in the
onpopstate documentation are met.public void go(int steps)
History.HistoryStateChangeEvent
to be fired
asynchronously if the conditions described in the
onpopstate documentation are met.steps
- the number of steps to navigate, positive numbers navigate
forward, negative numbers backward. 0
causes the
current page to be reloadedCopyright © 2023. All rights reserved.