use hash history for initial location
This commit is contained in:
@@ -189,9 +189,16 @@ function choo () {
|
|||||||
// initial application state model
|
// initial application state model
|
||||||
// obj -> obj
|
// obj -> obj
|
||||||
function appInit (opts) {
|
function appInit (opts) {
|
||||||
|
var initialLocation
|
||||||
|
if (opts.history !== false) {
|
||||||
|
initialLocation = document.location.href
|
||||||
|
} else {
|
||||||
|
initialLocation = hashMatch(document.location.hash)
|
||||||
|
}
|
||||||
|
|
||||||
const model = {
|
const model = {
|
||||||
namespace: 'app',
|
namespace: 'app',
|
||||||
state: { location: document.location.href },
|
state: { location: initialLocation },
|
||||||
subscriptions: [],
|
subscriptions: [],
|
||||||
reducers: {
|
reducers: {
|
||||||
// handle href links
|
// handle href links
|
||||||
@@ -206,8 +213,10 @@ function appInit (opts) {
|
|||||||
// enable catching <href a=""></href> links
|
// enable catching <href a=""></href> links
|
||||||
// enable HTML5 history API
|
// enable HTML5 history API
|
||||||
if (opts.href !== false) pushLocationSub(href)
|
if (opts.href !== false) pushLocationSub(href)
|
||||||
if (opts.history !== false) pushLocationSub(history)
|
if (opts.history !== false) {
|
||||||
if (opts.hash !== false) {
|
pushLocationSub(history)
|
||||||
|
// otherwise enable hash history
|
||||||
|
} else {
|
||||||
pushLocationSub(function (navigate) {
|
pushLocationSub(function (navigate) {
|
||||||
hash(function (fragment) {
|
hash(function (fragment) {
|
||||||
navigate(hashMatch(fragment))
|
navigate(hashMatch(fragment))
|
||||||
|
|||||||
Reference in New Issue
Block a user