@@ -391,7 +391,10 @@ async function* handleSSGRoute(
391391 meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
392392 }
393393
394- if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
394+ if (
395+ ( currentRoutePath . includes ( '**' ) && ! getPrerenderParams ) ||
396+ ! URL_PARAMETER_REGEXP . test ( currentRoutePath )
397+ ) {
395398 // Route has no parameters
396399 yield {
397400 ...meta ,
@@ -415,7 +418,9 @@ async function* handleSSGRoute(
415418
416419 if ( serverConfigRouteTree ) {
417420 // Automatically resolve dynamic parameters for nested routes.
418- const catchAllRoutePath = joinUrlParts ( currentRoutePath , '**' ) ;
421+ const catchAllRoutePath = currentRoutePath . endsWith ( '**' )
422+ ? currentRoutePath
423+ : joinUrlParts ( currentRoutePath , '**' ) ;
419424 const match = serverConfigRouteTree . match ( catchAllRoutePath ) ;
420425 if ( match && match . renderMode === RenderMode . Prerender && ! ( 'getPrerenderParams' in match ) ) {
421426 serverConfigRouteTree . insert ( catchAllRoutePath , {
@@ -429,20 +434,39 @@ async function* handleSSGRoute(
429434 const parameters = await runInInjectionContext ( parentInjector , ( ) => getPrerenderParams ( ) ) ;
430435 try {
431436 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 ) {
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 ( 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+ }
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 ( ! path . includes ( '**' ) && path . includes ( '*' ) && 'getPrerenderParams' in metadata ) {
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