Interface BrowsingHistory
- All Known Subinterfaces:
WindowHistoryProvider
- All Known Implementing Classes:
BrowsingHistoryBase
,MemoryBrowsingHistory
,SubBrowsingHistory
public interface BrowsingHistory
Inspired from https://github.com/mjackson/history/blob/master/docs/Glossary.md#history
- Author:
- Bruno Salmon
-
Method Summary
Modifier and TypeMethodDescriptioncreateHistoryLocation
(String path, ReadOnlyAstObject state) createPathStateLocation
(String path, ReadOnlyAstObject state) getPath
(PathStateLocation location) Creating URLs ******************************************************* Additionally, history objects can be used to create URL paths and/or hrefs for<a>
tags that link to various places in your app.void
go
(int offset) Differential navigation method.default void
goBack()
Go back to the previous history entry.default void
Go forward to the next history entry.boolean
void
listen
(Handler<BrowsingHistoryLocation> listener) Listen for changes to the current location.default void
listenBefore
(Function<BrowsingHistoryLocation, Boolean> transitionHook) Sometimes you may want to prevent the user from going to a different page.void
listenBeforeAsync
(Function<BrowsingHistoryLocation, Future<Boolean>> transitionHook) If your transition hook needs to execute asynchronously, you can return a future boolean.void
listenBeforeUnload
(Function<BrowsingHistoryLocation, Boolean> transitionHook) A before unload hook is a function that is used in web browsers to prevent the user from navigating away from the page or closing the window.void
push
(PathStateLocation location) Push a new entry onto the history stack.default void
Push a new entry onto the history stack.default void
push
(String path, ReadOnlyAstObject state) Push a new entry onto the history stack.void
replace
(PathStateLocation location) Replace the current entry on the history stack.default void
Replace the current entry on the history stack.default void
replace
(String path, ReadOnlyAstObject state) Replace the current entry on the history stack.void
transitionTo
(BrowsingHistoryLocation location)
-
Method Details
-
getCurrentLocation
BrowsingHistoryLocation getCurrentLocation()- Returns:
- the current location
-
push
Push a new entry onto the history stack.- Parameters:
path
- A path string that represents a complete URL path. Path = Pathname + Search + Hash
-
push
Push a new entry onto the history stack.- Parameters:
path
- A path string that represents a complete URL path. Path = Pathname + Search + Hashstate
- A state object associated with this history entry
-
push
Push a new entry onto the history stack.- Parameters:
location
- A location descriptor object that uses a combination of pathname, search, hash, and state properties
-
replace
Replace the current entry on the history stack.- Parameters:
path
- A path string that represents a complete URL path. Path = Pathname + Search + Hash
-
replace
Replace the current entry on the history stack.- Parameters:
path
- A path string that represents a complete URL path. Path = Pathname + Search + Hashstate
- A state object associated with this history entry
-
replace
Replace the current entry on the history stack.- Parameters:
location
- A location descriptor object that uses a combination of pathname, search, hash, and state properties
-
transitionTo
-
go
void go(int offset) Differential navigation method.- Parameters:
offset
- the differential step from the current location.
-
goBack
default void goBack()Go back to the previous history entry. Same as go(-1). -
goForward
default void goForward()Go forward to the next history entry. Same as go(1). -
isGoingBackward
boolean isGoingBackward() -
listen
Listen for changes to the current location. -
listenBefore
Sometimes you may want to prevent the user from going to a different page. For example, if they are halfway finished filling out a long form, and they click the back button, you may want to prompt them to confirm they actually want to leave the page before they lose the information they've already entered.- Parameters:
transitionHook
- a hook function that takes the location and returns a boolean that tells if the transition is accepted (true) or prevented (false)
-
listenBeforeAsync
If your transition hook needs to execute asynchronously, you can return a future boolean. Note: If you do provide a callback argument, the transition will not proceed until you call it (i.e. listeners will not be notified of the new location)! If your app is slow for some reason, this could lead to a non-responsive UI.- Parameters:
transitionHook
- a hook asynchronous function that takes the location and returns a future boolean that will tell if the transition accepted (true) or prevented (false)
-
listenBeforeUnload
A before unload hook is a function that is used in web browsers to prevent the user from navigating away from the page or closing the window. history.listenBeforeUnload(() -> 'Are you sure you want to leave this page?'); Note that because of the nature of the beforeunload event all hooks must return synchronously. BrowsingHistory runs all hooks in the order they were registered and displays the first message that is returned.- Parameters:
transitionHook
-
-
getPath
Creating URLs ******************************************************* Additionally, history objects can be used to create URL paths and/or hrefs for<a>
tags that link to various places in your app. This is useful when using hash history to prefix URLs with a # or when using query support to automatically build query strings. String href = history.createHref('/the/path') -
createPathStateLocation
-
createHistoryLocation
-