pushstate-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

pushstate.js

pushstate.js adds a native way to listen for changes in the address bar, similar to how a pushstate event might work (if one existed). It works via an initializer function that sets up a MutationObserver, which fires an Event with the properties previous and current whenever the observer detects changes to the document's subtree or childList and the URL in the address bar (window.location.href) has also changed.

Installation

npm i pushstate-js

Usage

import intiailizePushstateEvent from 'pushstate-js';
intiailizePushstateEvent();

window.addEventListener('pushstate', ({ current, previous }) => {
  // do whatever you want with `current` and `previous`
});

It's that simple. Enjoy!

I'm happy to respond to and/or resolve any suggestions or bug reports, so feel free to open an issue.

Install

npm i pushstate-js

DownloadsWeekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

7.01 kB

Total Files

7

Last publish

Collaborators

  • brandonmcconnell