Skip to content

Commit 8369c6b

Browse files
committed
fix(hash): support unicode in initial route
1 parent 67950d1 commit 8369c6b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

examples/hash-mode/app.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Vue.use(VueRouter)
1010
const Home = { template: '<div>home</div>' }
1111
const Foo = { template: '<div>foo</div>' }
1212
const Bar = { template: '<div>bar</div>' }
13+
const Unicode = { template: '<div>unicode</div>' }
1314

1415
// 3. Create the router
1516
const router = new VueRouter({
@@ -18,7 +19,8 @@ const router = new VueRouter({
1819
routes: [
1920
{ path: '/', component: Home }, // all paths are defined without the hash.
2021
{ path: '/foo', component: Foo },
21-
{ path: '/bar', component: Bar }
22+
{ path: '/bar', component: Bar },
23+
{ path: '/é', component: Unicode }
2224
]
2325
})
2426

@@ -35,6 +37,7 @@ new Vue({
3537
<li><router-link to="/foo">/foo</router-link></li>
3638
<li><router-link to="/bar">/bar</router-link></li>
3739
<router-link tag="li" to="/bar">/bar</router-link>
40+
<li><router-link to="/é">/é</router-link></li>
3841
</ul>
3942
<router-view class="view"></router-view>
4043
</div>

src/history/hash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function getHash (): string {
102102
// consistent across browsers - Firefox will pre-decode it!
103103
const href = window.location.href
104104
const index = href.indexOf('#')
105-
return index === -1 ? '' : href.slice(index + 1)
105+
return index === -1 ? '' : decodeURI(href.slice(index + 1))
106106
}
107107

108108
function getUrl (path) {

test/e2e/specs/hash-mode.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module.exports = {
33
browser
44
.url('http://localhost:8080/hash-mode/')
55
.waitForElementVisible('#app', 1000)
6-
.assert.count('li', 4)
7-
.assert.count('li a', 3)
6+
.assert.count('li', 5)
7+
.assert.count('li a', 4)
88
.assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/')
99
.assert.attributeContains('li:nth-child(2) a', 'href', '/hash-mode/#/foo')
1010
.assert.attributeContains('li:nth-child(3) a', 'href', '/hash-mode/#/bar')
11+
.assert.attributeContains('li:nth-child(5) a', 'href', '/hash-mode/#/%C3%A9')
1112
.assert.containsText('.view', 'home')
1213

1314
.click('li:nth-child(2) a')
@@ -30,6 +31,9 @@ module.exports = {
3031
.url('http://localhost:8080/hash-mode/#/foo')
3132
.waitForElementVisible('#app', 1000)
3233
.assert.containsText('.view', 'foo')
34+
.url('http://localhost:8080/hash-mode/#/%C3%A9')
35+
.waitForElementVisible('#app', 1000)
36+
.assert.containsText('.view', 'unicode')
3337
.end()
3438
}
3539
}

0 commit comments

Comments
 (0)