]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: wrong order for params resolving in matcher
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 6 May 2019 15:29:05 +0000 (17:29 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 6 May 2019 15:29:05 +0000 (17:29 +0200)
src/matcher.ts

index 8be13b2d2cc3a78034b66183d9b551caf915454d..523d07ed684cd3cbd30d2fb98dced77414e8bee0 100644 (file)
@@ -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: [])