When you import this package, it adds a locationchange
event to window
that is dispatched whenever the URL changes
even when calling pushState
or replaceState
caused the change as well as when the browser's back or forward buttons are used.
It also adds pushstate
and replacestate
events to window
in case you want to listen to those specifically.
This packages is particularly usefull when you are using a single-page application (SPA) router that manipulates the URL
using the browser's history API ( history.pushState()
and history.replaceState()
), but does not trigger a page reload.
npm install @transformation-dev/locationchange
import '@transformation-dev/locationchange';