Skip to content

Commit 68b631d

Browse files
committed
feat: handle splats
1 parent 1e56d29 commit 68b631d

File tree

7 files changed

+60
-124
lines changed

7 files changed

+60
-124
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"vitepress-plugin-llms": "^1.7.3",
204204
"vitest": "^3.2.4",
205205
"vue": "^3.5.18",
206-
"vue-router": "https://pkg.pr.new/vue-router@34703fb",
206+
"vue-router": "https://pkg.pr.new/vue-router@2d1abf5",
207207
"vue-router-mock": "^2.0.0",
208208
"vue-tsc": "^3.0.5",
209209
"vuefire": "^3.2.2",

playground-experimental/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
"mande": "^2.0.9",
1919
"pinia": "^3.0.3",
2020
"vue": "^3.5.18",
21-
"vue-router": "https://pkg.pr.new/vue-router@34703fb"
21+
"vue-router": "https://pkg.pr.new/vue-router@2d1abf5"
2222
}
2323
}

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codegen/generateRouteResolver.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,43 @@ describe('generateRouteRecordPath', () => {
149149
),"
150150
`)
151151
})
152+
153+
it('works with a catch all route', () => {
154+
const node = new PrefixTree(DEFAULT_OPTIONS).insert(
155+
'[...all]',
156+
'[...all].vue'
157+
)
158+
expect(
159+
generateRouteRecordPath({ importsMap, node, paramParsersMap: new Map() })
160+
).toMatchInlineSnapshot(`
161+
"path: new MatcherPatternPathDynamic(
162+
/^\\/(.*)$/i,
163+
{
164+
all: {},
165+
},
166+
[1],
167+
),"
168+
`)
169+
})
170+
171+
it('works with a splat param with a prefix', () => {
172+
const node = new PrefixTree(DEFAULT_OPTIONS).insert(
173+
'a/some-[id]/[...all]',
174+
'a/some-[id]/[...all].vue'
175+
)
176+
expect(
177+
generateRouteRecordPath({ importsMap, node, paramParsersMap: new Map() })
178+
).toMatchInlineSnapshot(`
179+
"path: new MatcherPatternPathDynamic(
180+
/^\\/a\\/some-([^/]+?)\\/(.*)$/i,
181+
{
182+
id: {},
183+
all: {},
184+
},
185+
["a",["some-",0],1],
186+
),"
187+
`)
188+
})
152189
})
153190

154191
describe('generateRouteRecord', () => {

src/core/tree.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,13 @@ export class TreeNode {
329329
let node: TreeNode | undefined = this
330330

331331
while (node && !node.isRoot()) {
332-
const subSegments = node.value.subSegments.map(
333-
(segment) => (typeof segment === 'string' ? segment : 0) /* param */
332+
const subSegments = node.value.subSegments.map((segment) =>
333+
typeof segment === 'string'
334+
? segment
335+
: // param
336+
segment.isSplat
337+
? 1
338+
: 0
334339
)
335340

336341
if (subSegments.length > 1) {

src/runtime-experimental.ts

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/runtime.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ export function _mergeRouteRecordExperimental(
8080
},
8181
...routeRecords: Partial<DefinePage>[]
8282
) {
83-
return routeRecords.reduce((acc, routeRecord) => {
84-
Object.assign(acc, routeRecord)
85-
acc.meta = { ...acc.meta, ...routeRecord.meta }
86-
87-
return acc
88-
}, main)
83+
for (const record of routeRecords) {
84+
main.meta = { ...main.meta, ...record.meta }
85+
}
86+
return main
8987
}

0 commit comments

Comments
 (0)