]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: splat at root
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 27 Aug 2025 20:02:42 +0000 (22:02 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 27 Aug 2025 20:02:42 +0000 (22:02 +0200)
packages/router/src/experimental/route-resolver/matchers/matcher-pattern.spec.ts
packages/router/src/experimental/route-resolver/matchers/matcher-pattern.ts

index fc52ad67db3023dcee401353cb2494fe1b7daa18..ed1dc7d32addb9fa05fdc560a4aa48bf08913892 100644 (file)
@@ -272,6 +272,27 @@ describe('MatcherPatternPathDynamic', () => {
     expect(pattern.build({ pathMatch: '124/b' })).toBe('/teams/124/b')
   })
 
+  it('splat param without prefix', () => {
+    const pattern = new MatcherPatternPathDynamic(
+      /^\/(.*)$/,
+      {
+        pathMatch: [],
+      },
+      [0],
+      null
+    )
+    expect(pattern.match('/')).toEqual({ pathMatch: '' })
+    expect(pattern.match('/123/b')).toEqual({ pathMatch: '123/b' })
+    expect(pattern.match('/anything/goes/here')).toEqual({
+      pathMatch: 'anything/goes/here',
+    })
+
+    expect(pattern.build({ pathMatch: null })).toBe('/')
+    expect(pattern.build({ pathMatch: '' })).toBe('/')
+    expect(pattern.build({ pathMatch: '124' })).toBe('/124')
+    expect(pattern.build({ pathMatch: '124/b' })).toBe('/124/b')
+  })
+
   it('repeatable optional param', () => {
     const pattern = new MatcherPatternPathDynamic(
       /^\/teams(?:\/(.+?))?\/b$/i,
index b45e6ee66225c30c665493fa960a1b979cfdef6d..cf7c0cf30699b4988e074bbad007cc2d8136e829 100644 (file)
@@ -283,7 +283,7 @@ export class MatcherPatternPathDynamic<
      * no sense to build a path it cannot match.
      */
     return this.trailingSlash == null
-      ? path + (!value ? '/' : '')
+      ? path + (!value && path.at(-1) !== '/' ? '/' : '')
       : path.replace(RE_TRAILING_SLASHES, this.trailingSlash ? '/' : '')
   }
 }