-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(location): add a copy for params with named locations (#2802)
Closes #2800, #2938 * fix(normalizeLocation): add a copy for params with named locations * test: add test case for #2938
- Loading branch information
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Vue from 'vue' | ||
import VueRouter from 'vue-router' | ||
|
||
Vue.use(VueRouter) | ||
|
||
const Log = { | ||
template: `<div class="log">id: {{ $route.params.id }}, type: {{ $route.params.type }}</div>` | ||
} | ||
|
||
const Logs = { | ||
template: ` | ||
<div> | ||
<pre id="params">{{ to.params }}</pre> | ||
<router-link :to="to" class="child-link">{{ to.params.type }}</router-link> | ||
<router-view></router-view> | ||
</div> | ||
`, | ||
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: ` | ||
<div id="app"> | ||
<h1>Route params</h1> | ||
<ul> | ||
<li><router-link to="/items/1/logs">item #1</router-link></li> | ||
<li><router-link to="/items/2/logs">item #2</router-link></li> | ||
</ul> | ||
<router-view class="view"></router-view> | ||
</div> | ||
` | ||
}).$mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<link rel="stylesheet" href="/global.css"> | ||
<a href="/">← Examples index</a> | ||
<div id="app"></div> | ||
<script src="/__build__/shared.chunk.js"></script> | ||
<script src="/__build__/route-params.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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') | ||
.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') | ||
.click('.child-link') | ||
.assert.urlEquals('http://localhost:8080/route-params/items/2/logs/info') | ||
.assert.containsText('.log', 'id: 2, type: info') | ||
|
||
.end() | ||
} | ||
} |