detect-url-change
Version:
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.
33 lines (19 loc) • 851 B
Markdown
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.
```js
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.