diff --git a/src/create-matcher.js b/src/create-matcher.js index 8be8b980a..07987c431 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -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 } } diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index ea1ef3a29..ab52dfc77 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -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') @@ -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') @@ -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') diff --git a/test/unit/specs/create-matcher.spec.js b/test/unit/specs/create-matcher.spec.js index bb932c702..5028957e5 100644 --- a/test/unit/specs/create-matcher.spec.js +++ b/test/unit/specs/create-matcher.spec.js @@ -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 () { @@ -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' }) + }) })