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