This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) => { | |
m.call(history, state, title, url); | |
let e = new Event(m.name.toLowerCase()); | |
e.state = state; | |
dispatchEvent(e); | |
}; | |
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