Skip to content

Commit d7caf8e

Browse files
committed
Fix bug vuejs#1572
1 parent d543ca9 commit d7caf8e

File tree

6 files changed

+100
-2
lines changed

6 files changed

+100
-2
lines changed

examples/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h1>Vue Router Examples</h1>
1212
<li><a href="nested-routes">Nested Routes</a></li>
1313
<li><a href="named-routes">Named Routes</a></li>
1414
<li><a href="named-views">Named Views</a></li>
15+
<li><a href="nameed-change">Nameed Change</a></li>
1516
<li><a href="route-matching">Route Matching</a></li>
1617
<li><a href="active-links">Active Links</a></li>
1718
<li><a href="redirect">Redirect</a></li>

examples/nameed-change/app.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import Vue from 'vue'
2+
import VueRouter from 'vue-router'
3+
4+
Vue.use(VueRouter)
5+
6+
let count = 0
7+
8+
const Home = {
9+
template: `
10+
<div>
11+
<span>nav param:</span>
12+
<span class="count" v-text="$route.params.count"></span>
13+
<br>
14+
<button @click="update()">change param</button>
15+
16+
<br>
17+
<br>
18+
<div class="area">
19+
<router-link :to="{ name: 'app' }">
20+
router-link in Home
21+
</router-link>
22+
23+
<br>
24+
25+
<nested-component></nested-component>
26+
</div>
27+
</div>
28+
`,
29+
methods: {
30+
update () {
31+
count++
32+
this.$router.push({
33+
params: {
34+
count: count
35+
}
36+
})
37+
}
38+
}
39+
}
40+
41+
Vue.component('nested-component', {
42+
template: `
43+
<router-link :to="{ name: 'app' }">
44+
router-link in NestedComponent
45+
</router-link>
46+
`
47+
})
48+
49+
const router = new VueRouter({
50+
mode: 'history',
51+
routes: [
52+
{
53+
path: '/nameed-change/:count',
54+
name: 'app',
55+
component: Home
56+
},
57+
{
58+
path: '*',
59+
redirect: { name: 'app', params: { count: 0 }}
60+
}
61+
]
62+
})
63+
64+
new Vue({
65+
router,
66+
template: `
67+
<div id="app">
68+
<router-view></router-view>
69+
</div>
70+
`
71+
}).$mount('#app')
72+

examples/nameed-change/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<link rel="stylesheet" href="/global.css">
3+
<a href="/">&larr; Examples index</a>
4+
<div id="app"></div>
5+
<script src="/__build__/shared.js"></script>
6+
<script src="/__build__/nameed-change.js"></script>

src/components/link.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @flow */
22

33
import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
4+
import { assign } from '../util/location'
45
import { _Vue } from '../install'
56

67
// work around weird flow bug
@@ -31,7 +32,8 @@ export default {
3132
render (h: Function) {
3233
const router = this.$router
3334
const current = this.$route
34-
const { location, route, href } = router.resolve(this.to, current, this.append)
35+
const to = typeof this.to === 'string' ? this.to : assign({}, this.to) // Fix bug #1572
36+
const { location, route, href } = router.resolve(to, current, this.append)
3537

3638
const classes = {}
3739
const globalActiveClass = router.options.linkActiveClass

src/util/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function normalizeLocation (
6060
}
6161
}
6262

63-
function assign (a, b) {
63+
export function assign (a: Object, b: Object): Object {
6464
for (const key in b) {
6565
a[key] = b[key]
6666
}

test/e2e/specs/nameed-change.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
'nameed change': function (browser) {
3+
browser
4+
.url('http://localhost:8080/nameed-change/')
5+
.waitForElementVisible('#app', 1000)
6+
7+
.assert.urlEquals('http://localhost:8080/nameed-change/0')
8+
.assert.containsText('.count', '0')
9+
.assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/0')
10+
.assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/0')
11+
.click('button')
12+
.assert.containsText('.count', '1')
13+
.assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/1')
14+
.assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/1')
15+
.end()
16+
}
17+
}

0 commit comments

Comments
 (0)