browser-history-observer
v0.3.0
Published
Observer for HTML5 History API
Downloads
11
Maintainers
Readme
browser-history-observer (WIP)
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