From ad2a9884dba91e14b89d42170bad36f8eb89ee83 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 14 Jan 2018 17:25:34 +0100 Subject: [PATCH] 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 --- src/create-matcher.js | 3 ++- test/e2e/specs/route-matching.js | 4 ++-- test/unit/specs/create-matcher.spec.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/create-matcher.js b/src/create-matcher.js index 8be8b980a..9a8f56c55 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 || 'fullPath'] = val } } diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index ea1ef3a29..065b10827 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' + 'fullPath': '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' + 'fullPath': 'foo/bar' }) ) }, null, '/asterisk/foo/bar') diff --git a/test/unit/specs/create-matcher.spec.js b/test/unit/specs/create-matcher.spec.js index bb932c702..01befcf31 100644 --- a/test/unit/specs/create-matcher.spec.js +++ b/test/unit/specs/create-matcher.spec.js @@ -3,7 +3,7 @@ import { createMatcher } from '../../../src/create-matcher' const routes = [ { path: '/', name: 'home', component: { name: 'home' }}, - { path: '/foo', name: 'foo', component: { name: 'foo' }}, + { path: '/foo', name: 'foo', component: { name: 'foo' }} ] describe('Creating Matcher', function () {