Skip to content

Commit 4c51083

Browse files
committed
hash history: move absolute guard out of formatPath
1 parent 4f42085 commit 4c51083

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/history/hash.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export default class HashHistory {
1111
let self = this
1212
this.listener = function () {
1313
let path = location.hash
14-
let formattedPath = self.formatPath(path, true)
14+
let raw = path.replace(/^#!?/, '')
15+
// always
16+
if (raw.charAt(0) !== '/') {
17+
raw = '/' + raw
18+
}
19+
let formattedPath = self.formatPath(raw)
1520
if (formattedPath !== path) {
1621
location.replace(formattedPath)
1722
return
@@ -38,14 +43,10 @@ export default class HashHistory {
3843
}
3944
}
4045

41-
formatPath (path, expectAbsolute) {
42-
path = path.replace(/^#!?/, '')
46+
formatPath (path) {
4347
let isAbsoloute = path.charAt(0) === '/'
44-
if (expectAbsolute && !isAbsoloute) {
45-
path = '/' + path
46-
}
4748
let prefix = '#' + (this.hashbang ? '!' : '')
48-
return isAbsoloute || expectAbsolute
49+
return isAbsoloute
4950
? prefix + path
5051
: prefix + resolvePath(
5152
location.hash.replace(/^#!?/, ''),

0 commit comments

Comments
 (0)