Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ca1fccd

Browse files
authoredJul 2, 2018
fix(match): use pathMatch for the param of * routes (#1995)
* 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 * test(match): add test for asterisk route with props: true * refactor(match): use pathMatch instead of fullPath for unnamed params
1 parent 169a5a6 commit ca1fccd

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
 

‎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 || 'pathMatch'] = val
193194
}
194195
}
195196

‎test/e2e/specs/route-matching.js

+3-3
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+
pathMatch: '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+
pathMatch: 'foo/bar'
100100
})
101101
)
102102
}, null, '/asterisk/foo/bar')
@@ -120,7 +120,7 @@ module.exports = {
120120
route.matched[0].path === '/optional-group/(foo/)?bar' &&
121121
route.fullPath === '/optional-group/foo/bar' &&
122122
JSON.stringify(route.params) === JSON.stringify({
123-
0: 'foo/'
123+
pathMatch: 'foo/'
124124
})
125125
)
126126
}, null, '/optional-group/foo/bar')

‎test/unit/specs/create-matcher.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createMatcher } from '../../../src/create-matcher'
44
const routes = [
55
{ path: '/', name: 'home', component: { name: 'home' }},
66
{ path: '/foo', name: 'foo', component: { name: 'foo' }},
7+
{ path: '*', props: true, component: { name: 'notFound' }}
78
]
89

910
describe('Creating Matcher', function () {
@@ -32,4 +33,9 @@ describe('Creating Matcher', function () {
3233
match({ name: 'foo' }, routes[0])
3334
expect(console.warn).not.toHaveBeenCalled()
3435
})
36+
37+
it('matches asterisk routes with a default param name', function () {
38+
const { params } = match({ path: '/not-found' }, routes[0])
39+
expect(params).toEqual({ pathMatch: '/not-found' })
40+
})
3541
})

0 commit comments

Comments
 (0)