@@ -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,7 @@ async function* handleSSGRoute(
391392 meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
392393 }
393394
394- if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
395+ if ( ( isCatchAllRoute && ! getPrerenderParams ) || ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
395396 // Route has no parameters
396397 yield {
397398 ...meta ,
@@ -415,7 +416,9 @@ async function* handleSSGRoute(
415416
416417 if ( serverConfigRouteTree ) {
417418 // Automatically resolve dynamic parameters for nested routes.
418- const catchAllRoutePath = joinUrlParts ( currentRoutePath , '**' ) ;
419+ const catchAllRoutePath = isCatchAllRoute
420+ ? currentRoutePath
421+ : joinUrlParts ( currentRoutePath , '**' ) ;
419422 const match = serverConfigRouteTree . match ( catchAllRoutePath ) ;
420423 if ( match && match . renderMode === RenderMode . Prerender && ! ( 'getPrerenderParams' in match ) ) {
421424 serverConfigRouteTree . insert ( catchAllRoutePath , {
@@ -429,20 +432,38 @@ async function* handleSSGRoute(
429432 const parameters = await runInInjectionContext ( parentInjector , ( ) => getPrerenderParams ( ) ) ;
430433 try {
431434 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 isParamsArray = Array . isArray ( params ) ;
436+
437+ if ( isParamsArray ) {
438+ if ( ! isCatchAllRoute ) {
436439 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.` ,
441442 ) ;
442443 }
444+ } else if ( isCatchAllRoute ) {
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+ }
443450
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+ } ) ;
446467
447468 yield {
448469 ...meta ,
@@ -530,9 +551,9 @@ function buildServerConfigRouteTree({ routes, appShellRoute }: ServerRoutesConfi
530551 continue ;
531552 }
532553
533- if ( path . includes ( '* ') && 'getPrerenderParams' in metadata ) {
554+ if ( 'getPrerenderParams' in metadata && ! path . endsWith ( '/** ') && path . includes ( '*' ) ) {
534555 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.` ,
536557 ) ;
537558 continue ;
538559 }
0 commit comments