@@ -382,6 +382,7 @@ async function* handleSSGRoute(
382
382
383
383
const { route : currentRoutePath , fallback, ...meta } = metadata ;
384
384
const getPrerenderParams = 'getPrerenderParams' in meta ? meta . getPrerenderParams : undefined ;
385
+ const isCatchAllRoute = currentRoutePath . endsWith ( '**' ) ;
385
386
386
387
if ( 'getPrerenderParams' in meta ) {
387
388
delete meta [ 'getPrerenderParams' ] ;
@@ -391,7 +392,10 @@ async function* handleSSGRoute(
391
392
meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
392
393
}
393
394
394
- if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
395
+ if (
396
+ ( isCatchAllRoute && ! getPrerenderParams ) ||
397
+ ( ! isCatchAllRoute && ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) )
398
+ ) {
395
399
// Route has no parameters
396
400
yield {
397
401
...meta ,
@@ -415,7 +419,9 @@ async function* handleSSGRoute(
415
419
416
420
if ( serverConfigRouteTree ) {
417
421
// Automatically resolve dynamic parameters for nested routes.
418
- const catchAllRoutePath = joinUrlParts ( currentRoutePath , '**' ) ;
422
+ const catchAllRoutePath = isCatchAllRoute
423
+ ? currentRoutePath
424
+ : joinUrlParts ( currentRoutePath , '**' ) ;
419
425
const match = serverConfigRouteTree . match ( catchAllRoutePath ) ;
420
426
if ( match && match . renderMode === RenderMode . Prerender && ! ( 'getPrerenderParams' in match ) ) {
421
427
serverConfigRouteTree . insert ( catchAllRoutePath , {
@@ -429,20 +435,38 @@ async function* handleSSGRoute(
429
435
const parameters = await runInInjectionContext ( parentInjector , ( ) => getPrerenderParams ( ) ) ;
430
436
try {
431
437
for ( const params of parameters ) {
432
- const routeWithResolvedParams = currentRoutePath . replace ( URL_PARAMETER_REGEXP , ( match ) => {
433
- const parameterName = match . slice ( 1 ) ;
434
- const value = params [ parameterName ] ;
435
- if ( typeof value !== 'string' ) {
438
+ const isParamsArray = Array . isArray ( params ) ;
439
+
440
+ if ( isParamsArray ) {
441
+ if ( ! isCatchAllRoute ) {
436
442
throw new Error (
437
- `The 'getPrerenderParams' function defined for the '${ stripLeadingSlash ( currentRoutePath ) } ' route ` +
438
- `returned a non-string value for parameter '${ parameterName } '. ` +
439
- `Please make sure the 'getPrerenderParams' function returns values for all parameters ` +
440
- 'specified in this route.' ,
443
+ `The 'getPrerenderParams' function for the '${ stripLeadingSlash ( currentRoutePath ) } ' ` +
444
+ `route returned an array '${ JSON . stringify ( params ) } ', which is not valid for catch-all routes.` ,
441
445
) ;
442
446
}
447
+ } else if ( isCatchAllRoute ) {
448
+ throw new Error (
449
+ `The 'getPrerenderParams' function for the '${ stripLeadingSlash ( currentRoutePath ) } ' ` +
450
+ `route returned an object '${ JSON . stringify ( params ) } ', which is not valid for parameterized routes.` ,
451
+ ) ;
452
+ }
443
453
444
- return value ;
445
- } ) ;
454
+ const routeWithResolvedParams = isParamsArray
455
+ ? currentRoutePath . replace ( '**' , params . join ( '/' ) )
456
+ : currentRoutePath . replace ( URL_PARAMETER_REGEXP , ( match ) => {
457
+ const parameterName = match . slice ( 1 ) ;
458
+ const value = params [ parameterName ] ;
459
+ if ( typeof value !== 'string' ) {
460
+ throw new Error (
461
+ `The 'getPrerenderParams' function defined for the '${ stripLeadingSlash ( currentRoutePath ) } ' route ` +
462
+ `returned a non-string value for parameter '${ parameterName } '. ` +
463
+ `Please make sure the 'getPrerenderParams' function returns values for all parameters ` +
464
+ 'specified in this route.' ,
465
+ ) ;
466
+ }
467
+
468
+ return value ;
469
+ } ) ;
446
470
447
471
yield {
448
472
...meta ,
@@ -530,9 +554,9 @@ function buildServerConfigRouteTree({ routes, appShellRoute }: ServerRoutesConfi
530
554
continue ;
531
555
}
532
556
533
- if ( path . includes ( '* ') && 'getPrerenderParams' in metadata ) {
557
+ if ( 'getPrerenderParams' in metadata && ! path . endsWith ( '/** ') && path . includes ( '*' ) ) {
534
558
errors . push (
535
- `Invalid '${ path } ' route configuration: 'getPrerenderParams' cannot be used with a '*' or '**' route.` ,
559
+ `Invalid '${ path } ' route configuration: 'getPrerenderParams' cannot be used with a '*' route.` ,
536
560
) ;
537
561
continue ;
538
562
}
0 commit comments