Add hook for replaceState (#494)

* Add hook for replaceState

* Clarify why replaceState is dangerous
This commit is contained in:
Emil Bay
2017-05-19 14:56:45 +02:00
committed by Yoshua Wuyts
parent 1d8fd02da2
commit 736e4b4514
2 changed files with 7 additions and 3 deletions
+6 -3
View File
@@ -55,13 +55,16 @@ function Choo (opts) {
bus.emit('pushState')
})
bus.prependListener('pushState', function (href) {
if (href) window.history.pushState({}, null, href)
bus.prependListener('pushState', updateHistory.bind(null, 'push'))
bus.prependListener('replaceState', updateHistory.bind(null, 'replace'))
function updateHistory (mode) {
if (href) window.history[mode + 'State']({}, null, href)
bus.emit('render')
setTimeout(function () {
scrollIntoView()
}, 0)
})
}
if (opts.href !== false) {
nanohref(function (location) {