|
1 | 1 | var scrollToAnchor = require('scroll-to-anchor') |
2 | 2 | var documentReady = require('document-ready') |
3 | | -var nanolocation = require('nanolocation') |
4 | 3 | var nanotiming = require('nanotiming') |
5 | 4 | var nanorouter = require('nanorouter') |
6 | 5 | var nanomorph = require('nanomorph') |
@@ -39,8 +38,8 @@ function Choo (opts) { |
39 | 38 | // properties for internal use only |
40 | 39 | this._historyEnabled = opts.history === undefined ? true : opts.history |
41 | 40 | this._hrefEnabled = opts.href === undefined ? true : opts.href |
| 41 | + this._hashEnabled = opts.hash === undefined ? true : opts.hash |
42 | 42 | this._hasWindow = typeof window !== 'undefined' |
43 | | - this._createLocation = nanolocation |
44 | 43 | this._cache = opts.cache |
45 | 44 | this._loaded = false |
46 | 45 | this._stores = [] |
@@ -128,8 +127,11 @@ Choo.prototype.start = function () { |
128 | 127 | if (self._hrefEnabled) { |
129 | 128 | nanohref(function (location) { |
130 | 129 | var href = location.href |
131 | | - var currHref = window.location.href |
132 | | - if (href === currHref) return |
| 130 | + var hash = location.hash |
| 131 | + if (href === window.location.href) { |
| 132 | + if (!this._hashEnabled && hash) scrollToAnchor(hash) |
| 133 | + return |
| 134 | + } |
133 | 135 | self.emitter.emit(self._events.PUSHSTATE, href) |
134 | 136 | }) |
135 | 137 | } |
@@ -224,10 +226,12 @@ Choo.prototype.toString = function (location, state) { |
224 | 226 | Choo.prototype._matchRoute = function (locationOverride) { |
225 | 227 | var location, queryString |
226 | 228 | if (locationOverride) { |
227 | | - location = locationOverride.replace(/\?.+$/, '') |
| 229 | + location = locationOverride.replace(/\?.+$/, '').replace(/\/$/, '') |
| 230 | + if (!this._hashEnabled) location = location.replace(/#.+$/, '') |
228 | 231 | queryString = locationOverride |
229 | 232 | } else { |
230 | | - location = this._createLocation() |
| 233 | + location = window.location.pathname.replace(/\/$/, '') |
| 234 | + if (this._hashEnabled) location += window.location.hash.replace(/^#/, '/') |
231 | 235 | queryString = window.location.search |
232 | 236 | } |
233 | 237 | var matched = this.router.match(location) |
|
0 commit comments