From 7e837a47eb4e90cefb8fa8c82472660a9c5c1a7a Mon Sep 17 00:00:00 2001 From: timwis Date: Sat, 4 Jun 2016 18:43:38 -0400 Subject: [PATCH] use hash history for initial location --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b3e2e4d..1a5274e 100644 --- a/index.js +++ b/index.js @@ -189,9 +189,16 @@ function choo () { // initial application state model // obj -> obj function appInit (opts) { + var initialLocation + if (opts.history !== false) { + initialLocation = document.location.href + } else { + initialLocation = hashMatch(document.location.hash) + } + const model = { namespace: 'app', - state: { location: document.location.href }, + state: { location: initialLocation }, subscriptions: [], reducers: { // handle href links @@ -206,8 +213,10 @@ function appInit (opts) { // enable catching links // enable HTML5 history API if (opts.href !== false) pushLocationSub(href) - if (opts.history !== false) pushLocationSub(history) - if (opts.hash !== false) { + if (opts.history !== false) { + pushLocationSub(history) + // otherwise enable hash history + } else { pushLocationSub(function (navigate) { hash(function (fragment) { navigate(hashMatch(fragment))