From 97d7122ff2a574ab53084b0a033c82b31baaf88a Mon Sep 17 00:00:00 2001 From: timwis Date: Sat, 4 Jun 2016 15:03:56 -0400 Subject: [PATCH] listen to hash changes --- index.js | 9 +++++++++ package.json | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ff6b089..b3e2e4d 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,8 @@ const history = require('sheet-router/history') const sheetRouter = require('sheet-router') const document = require('global/document') const href = require('sheet-router/href') +const hash = require('sheet-router/hash') +const hashMatch = require('hash-match') const sendAction = require('send-action') const mutate = require('xtend/mutable') const assert = require('assert') @@ -205,6 +207,13 @@ function appInit (opts) { // enable HTML5 history API if (opts.href !== false) pushLocationSub(href) if (opts.history !== false) pushLocationSub(history) + if (opts.hash !== false) { + pushLocationSub(function (navigate) { + hash(function (fragment) { + navigate(hashMatch(fragment)) + }) + }) + } return model diff --git a/package.json b/package.json index d9df638..551567e 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,9 @@ "license": "MIT", "dependencies": { "global": "^4.3.0", + "hash-match": "^1.0.2", "send-action": "^1.1.0", - "sheet-router": "^3.0.0", + "sheet-router": "^3.1.0", "xhr": "^2.2.0", "xtend": "^4.0.1", "yo-yo": "^1.2.0"