Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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