Pinafore-Web-Client-Frontend/src/routes/_utils/historyEvents.js

19 lines
463 B
JavaScript
Raw Normal View History

// hacky way to listen for pushState/replaceState changes
// per https://stackoverflow.com/a/25673911/680742
function wrapper (type) {
2019-08-03 22:49:37 +02:00
const orig = history[type]
return function () {
2019-08-03 22:49:37 +02:00
const result = orig.apply(this, arguments)
const e = new Event(type)
e.arguments = arguments
window.dispatchEvent(e)
return result
}
}
if (process.browser) {
history.pushState = wrapper('pushState')
history.replaceState = wrapper('replaceState')
2018-02-11 18:37:13 +01:00
}