@@ -391,7 +391,10 @@ async function* handleSSGRoute(
391
391
meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
392
392
}
393
393
394
- if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
394
+ if (
395
+ ( currentRoutePath . includes ( '**' ) && ! getPrerenderParams ) ||
396
+ ! URL_PARAMETER_REGEXP . test ( currentRoutePath )
397
+ ) {
395
398
// Route has no parameters
396
399
yield {
397
400
...meta ,
@@ -415,7 +418,9 @@ async function* handleSSGRoute(
415
418
416
419
if ( serverConfigRouteTree ) {
417
420
// Automatically resolve dynamic parameters for nested routes.
418
- const catchAllRoutePath = joinUrlParts ( currentRoutePath , '**' ) ;
421
+ const catchAllRoutePath = currentRoutePath . endsWith ( '**' )
422
+ ? currentRoutePath
423
+ : joinUrlParts ( currentRoutePath , '**' ) ;
419
424
const match = serverConfigRouteTree . match ( catchAllRoutePath ) ;
420
425
if ( match && match . renderMode === RenderMode . Prerender && ! ( 'getPrerenderParams' in match ) ) {
421
426
serverConfigRouteTree . insert ( catchAllRoutePath , {
@@ -429,20 +434,39 @@ async function* handleSSGRoute(
429
434
const parameters = await runInInjectionContext ( parentInjector , ( ) => getPrerenderParams ( ) ) ;
430
435
try {
431
436
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' ) {
437
+ const isWildcardRoute = currentRoutePath . includes ( '**' ) ;
438
+ const isParamsArray = Array . isArray ( params ) ;
439
+
440
+ if ( isParamsArray ) {
441
+ if ( ! isWildcardRoute ) {
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 ( isWildcardRoute ) {
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 ( ! path . includes ( '**' ) && path . includes ( '*' ) && 'getPrerenderParams' in metadata ) {
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