From 9fe3cefb73ce0d71fbea3091dd47a37e237edd11 Mon Sep 17 00:00:00 2001
From: zrh122 <1229550935@qq.com>
Date: Wed, 5 Jun 2019 14:29:53 +0800
Subject: [PATCH 1/2] fix(normalizeLocation): add a copy for params with named
locations
---
examples/index.html | 1 +
examples/route-params/app.js | 57 ++++++++++++++++++++++++++++++++
examples/route-params/index.html | 6 ++++
src/util/location.js | 7 +++-
test/e2e/specs/route-params.js | 23 +++++++++++++
5 files changed, 93 insertions(+), 1 deletion(-)
create mode 100644 examples/route-params/app.js
create mode 100644 examples/route-params/index.html
create mode 100644 test/e2e/specs/route-params.js
diff --git a/examples/index.html b/examples/index.html
index 9fcb249da..c0ee5bc16 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -17,6 +17,7 @@
Vue Router Examples
Redirect
Route Props
Route Alias
+ Route Params
Transitions
Data Fetching
Navigation Guards
diff --git a/examples/route-params/app.js b/examples/route-params/app.js
new file mode 100644
index 000000000..1e03c9b66
--- /dev/null
+++ b/examples/route-params/app.js
@@ -0,0 +1,57 @@
+import Vue from 'vue'
+import VueRouter from 'vue-router'
+
+Vue.use(VueRouter)
+
+const Log = {
+ template: `id: {{$route.params.id}}, type: {{$route.params.type}}
`
+}
+
+const Logs = {
+ template: `
+
+ {{to.params.type}}
+
+
+ `,
+ data () {
+ return {
+ to: {
+ name: 'items.logs.type',
+ params: { type: 'info' }
+ }
+ }
+ }
+}
+
+const router = new VueRouter({
+ mode: 'history',
+ base: __dirname,
+ routes: [
+ {
+ path: '/items/:id/logs',
+ component: Logs,
+ children: [
+ {
+ path: ':type',
+ name: 'items.logs.type',
+ component: Log
+ }
+ ]
+ }
+ ]
+})
+
+new Vue({
+ router,
+ template: `
+
+ `
+}).$mount('#app')
diff --git a/examples/route-params/index.html b/examples/route-params/index.html
new file mode 100644
index 000000000..939b0e9ff
--- /dev/null
+++ b/examples/route-params/index.html
@@ -0,0 +1,6 @@
+
+
+← Examples index
+
+
+
diff --git a/src/util/location.js b/src/util/location.js
index 176b50141..fb98d4537 100644
--- a/src/util/location.js
+++ b/src/util/location.js
@@ -18,7 +18,12 @@ export function normalizeLocation (
if (next._normalized) {
return next
} else if (next.name) {
- return extend({}, raw)
+ next = extend({}, raw)
+ const params = next.params
+ if (params && typeof params === 'object') {
+ next.params = extend({}, params)
+ }
+ return next
}
// relative params
diff --git a/test/e2e/specs/route-params.js b/test/e2e/specs/route-params.js
new file mode 100644
index 000000000..7b494607b
--- /dev/null
+++ b/test/e2e/specs/route-params.js
@@ -0,0 +1,23 @@
+module.exports = {
+ 'route-params': function (browser) {
+ browser
+ .url('http://localhost:8080/route-params/')
+ .waitForElementVisible('#app', 1000)
+ .assert.count('li a', 2)
+
+ // https://github.com/vuejs/vue-router/issues/2800
+ .click('li:nth-child(1) a')
+ .assert.urlEquals('http://localhost:8080/route-params/items/1/logs')
+ .click('.child-link')
+ .assert.urlEquals('http://localhost:8080/route-params/items/1/logs/info')
+ .assert.containsText('.log', 'id: 1, type: info')
+
+ .click('li:nth-child(2) a')
+ .assert.urlEquals('http://localhost:8080/route-params/items/2/logs')
+ .click('.child-link')
+ .assert.urlEquals('http://localhost:8080/route-params/items/2/logs/info')
+ .assert.containsText('.log', 'id: 2, type: info')
+
+ .end()
+ }
+}
From e0dcda8057e3ea29ea8a93603f2ed58714d1b0d1 Mon Sep 17 00:00:00 2001
From: Eduardo San Martin Morote
Date: Mon, 23 Sep 2019 11:32:11 +0200
Subject: [PATCH 2/2] test: add test case for #2938
---
examples/route-params/app.js | 5 +++--
test/e2e/specs/route-params.js | 3 +++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/examples/route-params/app.js b/examples/route-params/app.js
index 1e03c9b66..c9f4699e7 100644
--- a/examples/route-params/app.js
+++ b/examples/route-params/app.js
@@ -4,13 +4,14 @@ import VueRouter from 'vue-router'
Vue.use(VueRouter)
const Log = {
- template: `id: {{$route.params.id}}, type: {{$route.params.type}}
`
+ template: `id: {{ $route.params.id }}, type: {{ $route.params.type }}
`
}
const Logs = {
template: `
-
{{to.params.type}}
+
{{ to.params }}
+
{{ to.params.type }}
`,
diff --git a/test/e2e/specs/route-params.js b/test/e2e/specs/route-params.js
index 7b494607b..f5c6dc970 100644
--- a/test/e2e/specs/route-params.js
+++ b/test/e2e/specs/route-params.js
@@ -8,9 +8,12 @@ module.exports = {
// https://github.com/vuejs/vue-router/issues/2800
.click('li:nth-child(1) a')
.assert.urlEquals('http://localhost:8080/route-params/items/1/logs')
+ .assert.containsText('#params', JSON.stringify({ type: 'info' }, null, 2))
.click('.child-link')
.assert.urlEquals('http://localhost:8080/route-params/items/1/logs/info')
.assert.containsText('.log', 'id: 1, type: info')
+ // https://github.com/vuejs/vue-router/issues/2938
+ .assert.containsText('#params', JSON.stringify({ type: 'info' }, null, 2))
.click('li:nth-child(2) a')
.assert.urlEquals('http://localhost:8080/route-params/items/2/logs')