Nefariously Programmed Mecha

    This package has been deprecated

    Author message:

    This package is no longer being maintained. You should not use it.

    @scant/history

    0.1.2 • Public • Published

    @scant/history

    Dead simple browser history notifier.

    GitHub license npm

    Install

    yarn add @scant/history
    

    Usage

    import createHistory from '@scant/history';
    
    // configure the handler, passing in the window object and the onChange handler
    const historyHandler = createHistory(window, (payload) => {
      const [ location, state, title ] = payload;
      console.log('Browser history changed:', location.href);
    })
    
    // start listening for changes to the browser history
    historyHandler.start();
    
    // changes to the browser history, using the history api or change the hash, will trigger the handler
    
    // stop listening for history changes
    historyHandler.stop();
    

    The payload is an array, which contains location information, any state object, and a title.

    The object is a slice of the important parts of window.location, as well as a type property so you can tell if the event came from the use of history.pushState (or history.replaceState) or from browser history navigation. This includes the href, host, hostname, port, pathname, hash, and search, all taken from the location object when the history changed.

    Any state object or title comes form the use of pushState or replaceState.

    Keywords

    none

    Install

    npm i @scant/history

    DownloadsWeekly Downloads

    1

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    24.7 kB

    Total Files

    7

    Last publish

    Collaborators

    • w33ble