Easily detect changes in the browser URL. Works with any method that changes the URL without reloading the page, such as history.pushState()
, history.replaceState()
, history.back()
, etc.
import detectUrlChange from 'detect-url-change';
detectUrlChange.on('change', (newUrl) => {
console.log(`URL changed: ${newUrl}`);
});
The target object we can observe to detect URL changes.
Type: URLChangeEvent
.
Call with callback to invoke callback on URL change.
Call with event listener (callback) to unregister event listener for the change
event.