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 Details

    • getCurrentLocation

      BrowsingHistoryLocation getCurrentLocation()
      Returns:
      the current location
    • push

      default void push(String path)
      Push a new entry onto the history stack.
      Parameters:
      path - A path string that represents a complete URL path. Path = Pathname + Search + Hash
    • push

      default void push(String path, ReadOnlyAstObject state)
      Push a new entry onto the history stack.
      Parameters:
      path - A path string that represents a complete URL path. Path = Pathname + Search + Hash
      state - A state object associated with this history entry
    • push

      void push(PathStateLocation location)
      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

      default void replace(String path)
      Replace the current entry on the history stack.
      Parameters:
      path - A path string that represents a complete URL path. Path = Pathname + Search + Hash
    • replace

      default void replace(String path, ReadOnlyAstObject state)
      Replace the current entry on the history stack.
      Parameters:
      path - A path string that represents a complete URL path. Path = Pathname + Search + Hash
      state - A state object associated with this history entry
    • replace

      void replace(PathStateLocation location)
      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

      void transitionTo(BrowsingHistoryLocation location)
    • 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

      void listen(Handler<BrowsingHistoryLocation> listener)
      Listen for changes to the current location.
    • listenBefore

      default void listenBefore(Function<BrowsingHistoryLocation,Boolean> transitionHook)
      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

      void listenBeforeAsync(Function<BrowsingHistoryLocation,Future<Boolean>> transitionHook)
      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

      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. 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

      String 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. 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

      PathStateLocation createPathStateLocation(String path, ReadOnlyAstObject state)
    • createHistoryLocation

      BrowsingHistoryLocation createHistoryLocation(String path, ReadOnlyAstObject state)