@@ -382,6 +382,7 @@ async function* handleSSGRoute(
382382
383383 const { route : currentRoutePath , fallback, ...meta } = metadata ;
384384 const getPrerenderParams = 'getPrerenderParams' in meta ? meta . getPrerenderParams : undefined ;
385+ const isCatchAllRoute = currentRoutePath . endsWith ( '**' ) ;
385386
386387 if ( 'getPrerenderParams' in meta ) {
387388 delete meta [ 'getPrerenderParams' ] ;
@@ -391,7 +392,10 @@ async function* handleSSGRoute(
391392 meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
392393 }
393394
394- if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
395+ if (
396+ ( isCatchAllRoute && ! getPrerenderParams ) ||
397+ ( ! isCatchAllRoute && ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) )
398+ ) {
395399 // Route has no parameters
396400 yield {
397401 ...meta ,
@@ -415,7 +419,9 @@ async function* handleSSGRoute(
415419
416420 if ( serverConfigRouteTree ) {
417421 // Automatically resolve dynamic parameters for nested routes.
418- const catchAllRoutePath = joinUrlParts ( currentRoutePath , '**' ) ;
422+ const catchAllRoutePath = isCatchAllRoute
423+ ? currentRoutePath
424+ : joinUrlParts ( currentRoutePath , '**' ) ;
419425 const match = serverConfigRouteTree . match ( catchAllRoutePath ) ;
420426 if ( match && match . renderMode === RenderMode . Prerender && ! ( 'getPrerenderParams' in match ) ) {
421427 serverConfigRouteTree . insert ( catchAllRoutePath , {
@@ -429,20 +435,38 @@ async function* handleSSGRoute(
429435 const parameters = await runInInjectionContext ( parentInjector , ( ) => getPrerenderParams ( ) ) ;
430436 try {
431437 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 ) {
436442 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.` ,
441445 ) ;
442446 }
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+ }
443453
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+ } ) ;
446470
447471 yield {
448472 ...meta ,
@@ -530,9 +554,9 @@ function buildServerConfigRouteTree({ routes, appShellRoute }: ServerRoutesConfi
530554 continue ;
531555 }
532556
533- if ( path . includes ( '* ') && 'getPrerenderParams' in metadata ) {
557+ if ( 'getPrerenderParams' in metadata && ! path . endsWith ( '/** ') && path . includes ( '*' ) ) {
534558 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.` ,
536560 ) ;
537561 continue ;
538562 }
0 commit comments