From d7caf8e5729403d6309db08135e6cc19a5061660 Mon Sep 17 00:00:00 2001
From: lzxb <1340641314@qq.com>
Date: Fri, 1 Dec 2017 14:54:25 +0800
Subject: [PATCH] Fix bug #1572
---
examples/index.html | 1 +
examples/nameed-change/app.js | 72 +++++++++++++++++++++++++++++++
examples/nameed-change/index.html | 6 +++
src/components/link.js | 4 +-
src/util/location.js | 2 +-
test/e2e/specs/nameed-change.js | 17 ++++++++
6 files changed, 100 insertions(+), 2 deletions(-)
create mode 100644 examples/nameed-change/app.js
create mode 100644 examples/nameed-change/index.html
create mode 100644 test/e2e/specs/nameed-change.js
diff --git a/examples/index.html b/examples/index.html
index f2bdf7225..1e4465f4d 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -12,6 +12,7 @@
Vue Router Examples
Nested Routes
Named Routes
Named Views
+ Nameed Change
Route Matching
Active Links
Redirect
diff --git a/examples/nameed-change/app.js b/examples/nameed-change/app.js
new file mode 100644
index 000000000..fdbb2d0f1
--- /dev/null
+++ b/examples/nameed-change/app.js
@@ -0,0 +1,72 @@
+import Vue from 'vue'
+import VueRouter from 'vue-router'
+
+Vue.use(VueRouter)
+
+let count = 0
+
+const Home = {
+ template: `
+
+
nav param:
+
+
+
+
+
+
+
+
+ router-link in Home
+
+
+
+
+
+
+
+ `,
+ methods: {
+ update () {
+ count++
+ this.$router.push({
+ params: {
+ count: count
+ }
+ })
+ }
+ }
+}
+
+Vue.component('nested-component', {
+ template: `
+
+ router-link in NestedComponent
+
+ `
+})
+
+const router = new VueRouter({
+ mode: 'history',
+ routes: [
+ {
+ path: '/nameed-change/:count',
+ name: 'app',
+ component: Home
+ },
+ {
+ path: '*',
+ redirect: { name: 'app', params: { count: 0 }}
+ }
+ ]
+})
+
+new Vue({
+ router,
+ template: `
+
+
+
+ `
+}).$mount('#app')
+
diff --git a/examples/nameed-change/index.html b/examples/nameed-change/index.html
new file mode 100644
index 000000000..0cdb2262e
--- /dev/null
+++ b/examples/nameed-change/index.html
@@ -0,0 +1,6 @@
+
+
+← Examples index
+
+
+
diff --git a/src/components/link.js b/src/components/link.js
index 10d3d118d..9c15e16ae 100644
--- a/src/components/link.js
+++ b/src/components/link.js
@@ -1,6 +1,7 @@
/* @flow */
import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
+import { assign } from '../util/location'
import { _Vue } from '../install'
// work around weird flow bug
@@ -31,7 +32,8 @@ export default {
render (h: Function) {
const router = this.$router
const current = this.$route
- const { location, route, href } = router.resolve(this.to, current, this.append)
+ const to = typeof this.to === 'string' ? this.to : assign({}, this.to) // Fix bug #1572
+ const { location, route, href } = router.resolve(to, current, this.append)
const classes = {}
const globalActiveClass = router.options.linkActiveClass
diff --git a/src/util/location.js b/src/util/location.js
index 5e482aebe..7dc38b2f4 100644
--- a/src/util/location.js
+++ b/src/util/location.js
@@ -60,7 +60,7 @@ export function normalizeLocation (
}
}
-function assign (a, b) {
+export function assign (a: Object, b: Object): Object {
for (const key in b) {
a[key] = b[key]
}
diff --git a/test/e2e/specs/nameed-change.js b/test/e2e/specs/nameed-change.js
new file mode 100644
index 000000000..d19f71b73
--- /dev/null
+++ b/test/e2e/specs/nameed-change.js
@@ -0,0 +1,17 @@
+module.exports = {
+ 'nameed change': function (browser) {
+ browser
+ .url('http://localhost:8080/nameed-change/')
+ .waitForElementVisible('#app', 1000)
+
+ .assert.urlEquals('http://localhost:8080/nameed-change/0')
+ .assert.containsText('.count', '0')
+ .assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/0')
+ .assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/0')
+ .click('button')
+ .assert.containsText('.count', '1')
+ .assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/1')
+ .assert.attributeContains('.area a:nth-child(1)', 'href', '/nameed-change/1')
+ .end()
+ }
+}