From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 11:04:31 +0000 (+0200) Subject: feat: use existing params X-Git-Tag: v4.0.0-alpha.0~447 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9c418e71cd900d256430e527b8835a44e250d35;p=thirdparty%2Fvuejs%2Frouter.git feat: use existing params --- diff --git a/__tests__/matcher.spec.js b/__tests__/matcher.spec.js index e38de67e..fe7717e7 100644 --- a/__tests__/matcher.spec.js +++ b/__tests__/matcher.spec.js @@ -113,6 +113,23 @@ describe('Router Matcher', () => { } ) }) + + it('keep params if not provided', () => { + assertRecordMatch( + { path: '/users/:id/m/:role', name: 'UserEdit', component }, + {}, + { + name: 'UserEdit', + path: '/users/ed/m/user', + params: { id: 'ed', role: 'user' }, + }, + { + path: '/users/ed/m/user', + name: 'UserEdit', + params: { id: 'ed', role: 'user' }, + } + ) + }) }) }) }) diff --git a/src/matcher.ts b/src/matcher.ts index f49d0426..00d0fd8f 100644 --- a/src/matcher.ts +++ b/src/matcher.ts @@ -105,10 +105,12 @@ export class RouterMatcher { if (!matcher) throw new NoRouteMatchError(currentLocation, location) + let params = location.params ? location.params : currentLocation.params + return { name: currentLocation.name, - path: matcher.resolve(location.params), - params: location.params || {}, + path: matcher.resolve(params), + params, } } }