]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(matcher): repeated params
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 12 Oct 2019 13:04:19 +0000 (15:04 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 12 Oct 2019 13:04:19 +0000 (15:04 +0200)
__tests__/matcher.spec.ts
explorations/html5.ts
src/matcher.ts
src/router.ts

index 238d340c01f7e2f5a84655083f197d02a3fbba56..734a08cba74f4b5e0e54f65898163065fe4b8163 100644 (file)
@@ -116,6 +116,31 @@ describe('Router Matcher', () => {
         )
       })
 
+      it('resolves an array of params for a repeatable params', () => {
+        assertRecordMatch(
+          { path: '/a/:p+', name: 'a', components },
+          { name: 'a', params: { p: ['b', 'c', 'd'] } },
+          { name: 'a', path: '/a/b/c/d', params: { p: ['b', 'c', 'd'] } }
+        )
+      })
+
+      it('resolves single params for a repeatable params', () => {
+        assertRecordMatch(
+          { path: '/a/:p+', name: 'a', components },
+          { name: 'a', params: { p: 'b' } },
+          { name: 'a', path: '/a/b', params: { p: 'b' } }
+        )
+      })
+
+      it('keeps repeated params as a single one when provided through path', () => {
+        assertRecordMatch(
+          { path: '/a/:p+', name: 'a', components },
+          { path: '/a/b/c' },
+          // TODO: maybe it should consistently be an array for repeated params
+          { name: 'a', params: { p: 'b/c' } }
+        )
+      })
+
       it('resolves a path with multiple params', () => {
         assertRecordMatch(
           { path: '/users/:id/:other', name: 'User', components },
index abaaebbff6a7f43ddfff4d22ea1e9b5c396fbef5..7dacde96d6f8b1b974bfc5dd14da325c677b39a0 100644 (file)
@@ -139,6 +139,7 @@ const router = new Router({
       ],
     },
     { path: '/with-data', component: ComponentWithData, name: 'WithData' },
+    { path: '/rep/:a*', component: component, name: 'repeat' },
     // { path: /^\/about\/?$/, component },
   ],
   async scrollBehavior(to, from, savedPosition) {
index a283776cf62f4ebe3655adbd40794008fe515b4d..387bcd41ea43cc95aaa9c696974f6676252dbe78 100644 (file)
@@ -330,6 +330,7 @@ export class RouterMatcher {
   /**
    * Transforms a MatcherLocation object into a normalized location
    * @param location MatcherLocation to resolve to a url
+   * @param currentLocation MatcherLocationNormalized of the current location
    */
   resolve(
     location: Readonly<MatcherLocation>,
index cb341618c7fcec8cfe4de24fffd282e5fe74a9a7..20d63d3348af6606532690cef1d097414f8e9d36 100644 (file)
@@ -5,6 +5,7 @@ import {
   normalizeQuery,
   HistoryLocationNormalized,
   START,
+  NavigationDirection,
 } from './history/common'
 import { RouterMatcher } from './matcher'
 import {
@@ -44,7 +45,6 @@ interface ScrollBehavior {
 export interface RouterOptions {
   history: RouterHistory
   routes: RouteRecord[]
-  // TODO: async version
   scrollBehavior?: ScrollBehavior
 }
 
@@ -124,14 +124,14 @@ export class Router {
           // Maybe we could write the length the first time we do a navigation and use that for direction
           // TODO: this doesn't work if the user directly calls window.history.go(-n) with n > 1
           // We can override the go method to retrieve the number but not sure if all browsers allow that
-          // if (info.direction === NavigationDirection.back) {
-          // this.history.forward(false)
-          // } else {
-          // TODO: go back because we cancelled, then
-          // or replace and not discard the rest of history. Check issues, there was one talking about this
-          // behaviour, maybe we can do better
-          // this.history.back(false)
-          // }
+          if (info.direction === NavigationDirection.back) {
+            this.history.forward(false)
+          } else {
+            // TODO: go back because we cancelled, then
+            // or replace and not discard the rest of history. Check issues, there was one talking about this
+            // behaviour, maybe we can do better
+            this.history.back(false)
+          }
         } else {
           this.triggerError(error, false)
         }