Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajhsu/onroutechange
Listen to route changes for single-page applications.
https://github.com/ajhsu/onroutechange
Last synced: 15 days ago
JSON representation
Listen to route changes for single-page applications.
- Host: GitHub
- URL: https://github.com/ajhsu/onroutechange
- Owner: ajhsu
- License: mit
- Created: 2018-07-25T05:59:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-12T02:38:46.000Z (over 1 year ago)
- Last Synced: 2024-12-07T19:21:24.868Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 396 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# onroutechange
The polyfill enables you to listen to route changes by customized `window.onroutechange` callback.It's quite similar to [`window.onhashchange`](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onhashchange) API, but for `history.pushState`. Could be useful for single-page applications.
## Usage
Step1. Insert the following script tag into your webpage:
```html```
Step2. Register the `window.onroutechange` callback, for example:
```js
window.onroutechange = function(state) {
console.log('Route updated!');
};
```## License
MIT