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