Skip to content

Commit 60a5b58

Browse files
committed
Allow route to use current params to fill ones it does not provide
1 parent 2c8e3c0 commit 60a5b58

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/components/link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
const router = this.$router
2828
const current = this.$route
2929
const to = normalizeLocation(this.to, current, this.append)
30-
const resolved = router.match(to)
30+
const resolved = router.match(to, current)
3131
const fullPath = resolved.redirectedFrom || resolved.fullPath
3232
const base = router.history.base
3333
const href = createHref(base, fullPath, router.mode)

src/create-matcher.js

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
3131

3232
if (name) {
3333
const record = nameMap[name]
34+
35+
if (typeof location.params !== 'object') {
36+
location.params = {}
37+
}
38+
39+
if (currentRoute && typeof currentRoute.params === 'object') {
40+
for (const key in currentRoute.params) {
41+
if (!(key in location.params)) {
42+
location.params[key] = currentRoute.params[key]
43+
}
44+
}
45+
}
46+
3447
if (record) {
3548
location.path = fillParams(record.path, location.params, `named route "${name}"`)
3649
return _createRoute(record, location, redirectedFrom)

0 commit comments

Comments
 (0)