Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(match): use pathMatch for the param of * routes #1995

Merged
merged 3 commits into from Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/create-matcher.js
Expand Up @@ -189,7 +189,8 @@ function matchRoute (
const key = regex.keys[i - 1]
const val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]
if (key) {
params[key.name] = val
// Fix #1994: using * with props: true generates a param named 0
params[key.name || 'pathMatch'] = val
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/route-matching.js
Expand Up @@ -83,7 +83,7 @@ module.exports = {
route.matched[0].path === '/asterisk/*' &&
route.fullPath === '/asterisk/foo' &&
JSON.stringify(route.params) === JSON.stringify({
0: 'foo'
pathMatch: 'foo'
})
)
}, null, '/asterisk/foo')
Expand All @@ -96,7 +96,7 @@ module.exports = {
route.matched[0].path === '/asterisk/*' &&
route.fullPath === '/asterisk/foo/bar' &&
JSON.stringify(route.params) === JSON.stringify({
0: 'foo/bar'
pathMatch: 'foo/bar'
})
)
}, null, '/asterisk/foo/bar')
Expand All @@ -120,7 +120,7 @@ module.exports = {
route.matched[0].path === '/optional-group/(foo/)?bar' &&
route.fullPath === '/optional-group/foo/bar' &&
JSON.stringify(route.params) === JSON.stringify({
0: 'foo/'
pathMatch: 'foo/'
})
)
}, null, '/optional-group/foo/bar')
Expand Down
6 changes: 6 additions & 0 deletions test/unit/specs/create-matcher.spec.js
Expand Up @@ -4,6 +4,7 @@ import { createMatcher } from '../../../src/create-matcher'
const routes = [
{ path: '/', name: 'home', component: { name: 'home' }},
{ path: '/foo', name: 'foo', component: { name: 'foo' }},
{ path: '*', props: true, component: { name: 'notFound' }}
]

describe('Creating Matcher', function () {
Expand Down Expand Up @@ -32,4 +33,9 @@ describe('Creating Matcher', function () {
match({ name: 'foo' }, routes[0])
expect(console.warn).not.toHaveBeenCalled()
})

it('matches asterisk routes with a default param name', function () {
const { params } = match({ path: '/not-found' }, routes[0])
expect(params).toEqual({ pathMatch: '/not-found' })
})
})