From c2e4bb49634bd75ba6377ee90ab97775441a2038 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 22 Mar 2017 20:42:53 +0100 Subject: [PATCH] fix pushState event (#434) --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index ab60885..ce5f6a5 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,12 @@ function Framework (opts) { if (opts.history !== false) { onHistoryChange(function (href) { - bus.emit('pushState', window.location.href) + bus.emit('pushState') + }) + + bus.on('pushState', function (href) { + if (href) window.history.pushState({}, null, href) + bus.emit('render') scrollIntoView() }) @@ -66,10 +71,7 @@ function Framework (opts) { var href = location.href var currHref = window.location.href if (href === currHref) return - window.history.pushState({}, null, href) - bus.emit('pushState', window.location.href) - bus.emit('render') - scrollIntoView() + bus.emit('pushState', href) }) } }