url-observer
URLObserver observes URL changes in web browsers
Inspired by PerformanceObserver but for observing history on browsers.
Table of contents
Pre-requisites
Installation
$ npm install url-observer
Usage
import 'url-observer';
const observer = new URLObserver((list, observer) => {
for (const entry of list.getEntries()) {
}
});
const routes = [
/^\/test$\//i,
/^\/test\/(?<test>[^\/]+)$/i,
];
const options = {
dwellTime: 2e3,
debug: false,
matcherCallback() {
},
};
observe.observe(routes, options);
observer.add({
handleEvent: () => {
return true;
}
pathRegExp: routes[0],
scope: '',
});
observer.add({ pathRegExp: /^\/test2$/i });
observer.disconnect();
const {
found,
params,
} = observer.match();
observer.remove(routes[0]);
observer.remove(routes[1], '456');
observer.takeRecords();
await observer.updateHistory('/test/789');
await observer.updateHistory('/test/456', '456');
API References
Contributing
Code of Conduct
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
License
MIT License © Rong Sen Ng