From: Eduardo San Martin Morote Date: Mon, 6 May 2019 15:29:05 +0000 (+0200) Subject: fix: wrong order for params resolving in matcher X-Git-Tag: v4.0.0-alpha.0~388 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc3ff07b026855db3c1fb1bebbdfedc60fa88e46;p=thirdparty%2Fvuejs%2Frouter.git fix: wrong order for params resolving in matcher --- diff --git a/src/matcher.ts b/src/matcher.ts index 8be13b2d..523d07ed 100644 --- a/src/matcher.ts +++ b/src/matcher.ts @@ -106,15 +106,16 @@ export class RouterMatcher { if ('path' in location) { matcher = this.matchers.find(m => m.re.test(location.path)) - // no need to resolve the path with the matcher as it was provided - path = location.path // TODO: should go away but stop matching // TODO: warning of unused params if provided if (!matcher) throw new NoRouteMatchError(currentLocation, location) + // no need to resolve the path with the matcher as it was provided + path = location.path name = matcher.record.name + // fill params const result = matcher.re.exec(path) if (!result) { @@ -163,11 +164,11 @@ export class RouterMatcher { matcher = this.matchers.find(m => m.record.name === location.name) if (!matcher) throw new NoRouteMatchError(currentLocation, location) - // TODO: check missing params - params = location.params || {} // TODO: normalize params name = matcher.record.name + params = location.params || {} // TODO: normalize params path = matcher.resolve(params) + // TODO: check missing params if ('redirect' in matcher.record) { const { redirect } = matcher.record @@ -195,18 +196,18 @@ export class RouterMatcher { // location is a relative path else if (currentLocation.name) { // we don't want to match an undefined name - params = location.params ? location.params : currentLocation.params matcher = this.matchers.find(m => m.record.name === currentLocation.name) if (!matcher) throw new NoRouteMatchError(currentLocation, location) - path = matcher.resolve(params) name = matcher.record.name + params = location.params || currentLocation.params + path = matcher.resolve(params) } else { // match by path - params = location.params ? location.params : currentLocation.params matcher = this.matchers.find(m => m.re.test(currentLocation.path)) if (!matcher) throw new NoRouteMatchError(currentLocation, location) - path = matcher.resolve(params) name = matcher.record.name + params = location.params || currentLocation.params + path = matcher.resolve(params) } // TODO: allow match without matching record (matched: [])