@@ -391,7 +391,7 @@ async function* handleSSGRoute(
391391 meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
392392 }
393393
394- if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
394+ if ( ! currentRoutePath . includes ( '**' ) && ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
395395 // Route has no parameters
396396 yield {
397397 ...meta ,
@@ -415,7 +415,9 @@ async function* handleSSGRoute(
415415
416416 if ( serverConfigRouteTree ) {
417417 // Automatically resolve dynamic parameters for nested routes.
418- const catchAllRoutePath = joinUrlParts ( currentRoutePath , '**' ) ;
418+ const catchAllRoutePath = currentRoutePath . endsWith ( '**' )
419+ ? currentRoutePath
420+ : joinUrlParts ( currentRoutePath , '**' ) ;
419421 const match = serverConfigRouteTree . match ( catchAllRoutePath ) ;
420422 if ( match && match . renderMode === RenderMode . Prerender && ! ( 'getPrerenderParams' in match ) ) {
421423 serverConfigRouteTree . insert ( catchAllRoutePath , {
@@ -429,20 +431,39 @@ async function* handleSSGRoute(
429431 const parameters = await runInInjectionContext ( parentInjector , ( ) => getPrerenderParams ( ) ) ;
430432 try {
431433 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' ) {
434+ const isWildcardRoute = currentRoutePath . includes ( '**' ) ;
435+ const isParamsArray = Array . isArray ( params ) ;
436+
437+ if ( isParamsArray ) {
438+ if ( ! isWildcardRoute ) {
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 ( isWildcardRoute ) {
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 ( ! path . includes ( '**' ) && path . includes ( '*' ) && 'getPrerenderParams' in metadata ) {
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