Skip to content

Commit

Permalink
fix(hash): support unicode in initial route
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 4, 2018
1 parent 67950d1 commit 8369c6b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion examples/hash-mode/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Vue.use(VueRouter)
const Home = { template: '<div>home</div>' }
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Unicode = { template: '<div>unicode</div>' }

// 3. Create the router
const router = new VueRouter({
Expand All @@ -18,7 +19,8 @@ const router = new VueRouter({
routes: [
{ path: '/', component: Home }, // all paths are defined without the hash.
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
{ path: '/bar', component: Bar },
{ path: '/é', component: Unicode }
]
})

Expand All @@ -35,6 +37,7 @@ new Vue({
<li><router-link to="/foo">/foo</router-link></li>
<li><router-link to="/bar">/bar</router-link></li>
<router-link tag="li" to="/bar">/bar</router-link>
<li><router-link to="/é">/é</router-link></li>
</ul>
<router-view class="view"></router-view>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/history/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function getHash (): string {
// consistent across browsers - Firefox will pre-decode it!
const href = window.location.href
const index = href.indexOf('#')
return index === -1 ? '' : href.slice(index + 1)
return index === -1 ? '' : decodeURI(href.slice(index + 1))
}

function getUrl (path) {
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/specs/hash-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module.exports = {
browser
.url('http://localhost:8080/hash-mode/')
.waitForElementVisible('#app', 1000)
.assert.count('li', 4)
.assert.count('li a', 3)
.assert.count('li', 5)
.assert.count('li a', 4)
.assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/')
.assert.attributeContains('li:nth-child(2) a', 'href', '/hash-mode/#/foo')
.assert.attributeContains('li:nth-child(3) a', 'href', '/hash-mode/#/bar')
.assert.attributeContains('li:nth-child(5) a', 'href', '/hash-mode/#/%C3%A9')
.assert.containsText('.view', 'home')

.click('li:nth-child(2) a')
Expand All @@ -30,6 +31,9 @@ module.exports = {
.url('http://localhost:8080/hash-mode/#/foo')
.waitForElementVisible('#app', 1000)
.assert.containsText('.view', 'foo')
.url('http://localhost:8080/hash-mode/#/%C3%A9')
.waitForElementVisible('#app', 1000)
.assert.containsText('.view', 'unicode')
.end()
}
}

0 comments on commit 8369c6b

Please sign in to comment.