browser-history-observer
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

browser-history-observer (WIP)

npm version

Observer for HTML5 History API

Installation

# npm
npm install browser-history-observer

# yarn
yarn add browser-history-observer

Usage

import { HistoryObserver } from 'browser-history-observer';

const observer = new HistoryObserver();

// `popstate`
observer.onPopState(payload => {
  console.log(payload);
});

// `hashchange`
observer.onHashChange(payload => {
  console.log(payload);
});

// `popstate`/`history.pushState()`/`history.replaceState()`
observer.onHistoryChange(payload => {
  console.log(payload);
});

// `hashchange`/`history.pushState()`/`history.replaceState()`
observer.onHistoryHashChange(payload => {
  console.log(payload);
});

APIs

  • HistoryObserver
    • new HistoryObserver(options)
      • options.debug
    • HistoryObserver.prototype.dispose()
    • HistoryObserver.prototype.on(type, handler)
    • HistoryObserver.prototype.onLoad(handler)
    • HistoryObserver.prototype.onPopState(handler)
    • HistoryObserver.prototype.onHashChange(handler)
    • HistoryObserver.prototype.onPushState(handler)
    • HistoryObserver.prototype.onReplaceState(handler)
    • HistoryObserver.prototype.onHistoryChange(handler)
    • HistoryObserver.prototype.onHistoryHashChange(handler)
  • Utils
    • interceptHistory()
    • undoInterceptHistory()

License

MIT © Qingrong Ke

Package Sidebar

Install

npm i browser-history-observer

Weekly Downloads

3

Version

0.3.0

License

MIT

Unpacked Size

104 kB

Total Files

17

Last publish

Collaborators

  • dearke