Skip to content

Commit ad2a988

Browse files
committed
fix(match): use fullPath for the param of * routes
Fix #1994 Combining an asterisk route (*) with props: true would result in an error because the name of the param would be the number 0 making it an invalid attribute + the fact that vue passes props as attributes if they're not declared as props
1 parent 694a7af commit ad2a988

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Diff for: src/create-matcher.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ function matchRoute (
189189
const key = regex.keys[i - 1]
190190
const val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]
191191
if (key) {
192-
params[key.name] = val
192+
// Fix #1994: using * with props: true generates a param named 0
193+
params[key.name || 'fullPath'] = val
193194
}
194195
}
195196

Diff for: test/e2e/specs/route-matching.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = {
8383
route.matched[0].path === '/asterisk/*' &&
8484
route.fullPath === '/asterisk/foo' &&
8585
JSON.stringify(route.params) === JSON.stringify({
86-
0: 'foo'
86+
'fullPath': 'foo'
8787
})
8888
)
8989
}, null, '/asterisk/foo')
@@ -96,7 +96,7 @@ module.exports = {
9696
route.matched[0].path === '/asterisk/*' &&
9797
route.fullPath === '/asterisk/foo/bar' &&
9898
JSON.stringify(route.params) === JSON.stringify({
99-
0: 'foo/bar'
99+
'fullPath': 'foo/bar'
100100
})
101101
)
102102
}, null, '/asterisk/foo/bar')

Diff for: test/unit/specs/create-matcher.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createMatcher } from '../../../src/create-matcher'
33

44
const routes = [
55
{ path: '/', name: 'home', component: { name: 'home' }},
6-
{ path: '/foo', name: 'foo', component: { name: 'foo' }},
6+
{ path: '/foo', name: 'foo', component: { name: 'foo' }}
77
]
88

99
describe('Creating Matcher', function () {

0 commit comments

Comments
 (0)