bxo 0.0.5-dev.8 → 0.0.5-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +56 -6
- package/package.json +1 -1
package/index.ts
CHANGED
@@ -252,16 +252,38 @@ export default class BXO {
|
|
252
252
|
const routeSegments = route.path.split('/').filter(Boolean);
|
253
253
|
const pathSegments = pathname.split('/').filter(Boolean);
|
254
254
|
|
255
|
-
if (routeSegments.length !== pathSegments.length) continue;
|
256
|
-
|
257
255
|
const params: Record<string, string> = {};
|
258
256
|
let isMatch = true;
|
259
257
|
|
258
|
+
// Handle wildcard at the end (catch-all)
|
259
|
+
const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
|
260
|
+
|
261
|
+
if (hasWildcardAtEnd) {
|
262
|
+
// For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
|
263
|
+
if (pathSegments.length < routeSegments.length - 1) continue;
|
264
|
+
} else {
|
265
|
+
// For exact matching (with possible single-segment wildcards), lengths must match
|
266
|
+
if (routeSegments.length !== pathSegments.length) continue;
|
267
|
+
}
|
268
|
+
|
260
269
|
for (let i = 0; i < routeSegments.length; i++) {
|
261
270
|
const routeSegment = routeSegments[i];
|
262
271
|
const pathSegment = pathSegments[i];
|
263
272
|
|
264
|
-
if (!routeSegment
|
273
|
+
if (!routeSegment) {
|
274
|
+
isMatch = false;
|
275
|
+
break;
|
276
|
+
}
|
277
|
+
|
278
|
+
// Handle catch-all wildcard at the end
|
279
|
+
if (routeSegment === '*' && i === routeSegments.length - 1) {
|
280
|
+
// Wildcard at end matches remaining path segments
|
281
|
+
const remainingPath = pathSegments.slice(i).join('/');
|
282
|
+
params['*'] = remainingPath;
|
283
|
+
break;
|
284
|
+
}
|
285
|
+
|
286
|
+
if (!pathSegment) {
|
265
287
|
isMatch = false;
|
266
288
|
break;
|
267
289
|
}
|
@@ -269,6 +291,9 @@ export default class BXO {
|
|
269
291
|
if (routeSegment.startsWith(':')) {
|
270
292
|
const paramName = routeSegment.slice(1);
|
271
293
|
params[paramName] = decodeURIComponent(pathSegment);
|
294
|
+
} else if (routeSegment === '*') {
|
295
|
+
// Single segment wildcard
|
296
|
+
params['*'] = decodeURIComponent(pathSegment);
|
272
297
|
} else if (routeSegment !== pathSegment) {
|
273
298
|
isMatch = false;
|
274
299
|
break;
|
@@ -289,16 +314,38 @@ export default class BXO {
|
|
289
314
|
const routeSegments = route.path.split('/').filter(Boolean);
|
290
315
|
const pathSegments = pathname.split('/').filter(Boolean);
|
291
316
|
|
292
|
-
if (routeSegments.length !== pathSegments.length) continue;
|
293
|
-
|
294
317
|
const params: Record<string, string> = {};
|
295
318
|
let isMatch = true;
|
296
319
|
|
320
|
+
// Handle wildcard at the end (catch-all)
|
321
|
+
const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
|
322
|
+
|
323
|
+
if (hasWildcardAtEnd) {
|
324
|
+
// For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
|
325
|
+
if (pathSegments.length < routeSegments.length - 1) continue;
|
326
|
+
} else {
|
327
|
+
// For exact matching (with possible single-segment wildcards), lengths must match
|
328
|
+
if (routeSegments.length !== pathSegments.length) continue;
|
329
|
+
}
|
330
|
+
|
297
331
|
for (let i = 0; i < routeSegments.length; i++) {
|
298
332
|
const routeSegment = routeSegments[i];
|
299
333
|
const pathSegment = pathSegments[i];
|
300
334
|
|
301
|
-
if (!routeSegment
|
335
|
+
if (!routeSegment) {
|
336
|
+
isMatch = false;
|
337
|
+
break;
|
338
|
+
}
|
339
|
+
|
340
|
+
// Handle catch-all wildcard at the end
|
341
|
+
if (routeSegment === '*' && i === routeSegments.length - 1) {
|
342
|
+
// Wildcard at end matches remaining path segments
|
343
|
+
const remainingPath = pathSegments.slice(i).join('/');
|
344
|
+
params['*'] = remainingPath;
|
345
|
+
break;
|
346
|
+
}
|
347
|
+
|
348
|
+
if (!pathSegment) {
|
302
349
|
isMatch = false;
|
303
350
|
break;
|
304
351
|
}
|
@@ -306,6 +353,9 @@ export default class BXO {
|
|
306
353
|
if (routeSegment.startsWith(':')) {
|
307
354
|
const paramName = routeSegment.slice(1);
|
308
355
|
params[paramName] = decodeURIComponent(pathSegment);
|
356
|
+
} else if (routeSegment === '*') {
|
357
|
+
// Single segment wildcard
|
358
|
+
params['*'] = decodeURIComponent(pathSegment);
|
309
359
|
} else if (routeSegment !== pathSegment) {
|
310
360
|
isMatch = false;
|
311
361
|
break;
|