Skip to content

Instantly share code, notes, and snippets.

Created February 7, 2020 06:20
What would you like to do?
// we augment the window.history instance so that it will dispatch an event when using push/replace
// this allows us to create event stream and listen to all history state changes
export const patchHistory = history => {
const wrap = m => (state, title, url) => {, state, title, url);
let e = new Event(;
e.state = state;
history.pushState = wrap(history.pushState);
history.replaceState = wrap(history.replaceState);
return history;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment