Skip to content

Commit b5ff101

Browse files
committed
fix(hash): Properly handle encoded parameters in hash (close vuejs#2725)
Fix an issue where page browsing to a route and then reloading leads to inconsistent parameters and fullPath values.
1 parent 65de048 commit b5ff101

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

src/history/hash.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,15 @@ function ensureSlash (): boolean {
107107
}
108108

109109
export function getHash (): string {
110-
// We can't use window.location.hash here because it's not
111-
// consistent across browsers - Firefox will pre-decode it!
110+
// We need to get the raw hash to keep consistent behavior with routes
111+
// `fullPath` using encoded path. The params are decoded later in the
112+
// matcher.
112113
let href = window.location.href
113114
const index = href.indexOf('#')
114115
// empty path
115116
if (index < 0) return ''
116117

117118
href = href.slice(index + 1)
118-
// decode the hash but not the search or hash
119-
// as search(query) is already decoded
120-
// https://github.com/vuejs/vue-router/issues/2708
121-
const searchIndex = href.indexOf('?')
122-
if (searchIndex < 0) {
123-
const hashIndex = href.indexOf('#')
124-
if (hashIndex > -1) {
125-
href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex)
126-
} else href = decodeURI(href)
127-
} else {
128-
href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex)
129-
}
130-
131119
return href
132120
}
133121

0 commit comments

Comments
 (0)