@@ -727,8 +727,7 @@ export async function handleBuildComplete({
727727
728728 // need to add matching .rsc output
729729 if ( isAppPage ) {
730- const rscPathname =
731- ( output . pathname === '/' ? '/index' : output . pathname ) + '.rsc'
730+ const rscPathname = normalizePagePath ( output . pathname ) + '.rsc'
732731 outputs . appPages . push ( {
733732 ...output ,
734733 pathname : rscPathname ,
@@ -864,7 +863,7 @@ export async function handleBuildComplete({
864863 const dataPathname = path . posix . join (
865864 '/_next/data' ,
866865 buildId ,
867- page + '.json'
866+ normalizePagePath ( page ) + '.json'
868867 )
869868 outputs . pages . push ( {
870869 ...output ,
@@ -1002,9 +1001,8 @@ export async function handleBuildComplete({
10021001 if ( output . type === AdapterOutputType . APP_PAGE ) {
10031002 outputs . appPages . push ( {
10041003 ...output ,
1005- pathname :
1006- ( output . pathname === '/' ? '/index' : output . pathname ) + '.rsc' ,
1007- id : ( output . id === '/' ? '/index' : output . pathname ) + '.rsc' ,
1004+ pathname : normalizePagePath ( output . pathname ) + '.rsc' ,
1005+ id : normalizePagePath ( output . pathname ) + '.rsc' ,
10081006 } )
10091007 outputs . appPages . push ( output )
10101008 } else {
@@ -1058,15 +1056,18 @@ export async function handleBuildComplete({
10581056 }
10591057
10601058 if ( meta ?. segmentPaths ) {
1059+ const normalizedRoute = normalizePagePath ( route )
10611060 const segmentsDir = path . join (
10621061 appDistDir ,
1063- `${ route } ${ prefetchSegmentDirSuffix } `
1062+ `${ normalizedRoute } ${ prefetchSegmentDirSuffix } `
10641063 )
10651064
10661065 for ( const segmentPath of meta . segmentPaths ) {
10671066 const outputSegmentPath =
1068- path . join ( route + prefetchSegmentDirSuffix , segmentPath ) +
1069- prefetchSegmentSuffix
1067+ path . join (
1068+ normalizedRoute + prefetchSegmentDirSuffix ,
1069+ segmentPath
1070+ ) + prefetchSegmentSuffix
10701071
10711072 const fallbackPathname = path . join (
10721073 segmentsDir ,
@@ -1114,10 +1115,11 @@ export async function handleBuildComplete({
11141115 route : string ,
11151116 isAppPage : boolean
11161117 ) : Promise < AppRouteMeta > => {
1118+ const basename = route . endsWith ( '/' ) ? `${ route } index` : route
11171119 const meta : AppRouteMeta = isAppPage
11181120 ? JSON . parse (
11191121 await fs
1120- . readFile ( path . join ( appDistDir , `${ route } .meta` ) , 'utf8' )
1122+ . readFile ( path . join ( appDistDir , `${ basename } .meta` ) , 'utf8' )
11211123 . catch ( ( ) => '{}' )
11221124 )
11231125 : { }
@@ -1192,7 +1194,7 @@ export async function handleBuildComplete({
11921194
11931195 let filePath = path . join (
11941196 isAppPage ? appDistDir : pagesDistDir ,
1195- `${ route === '/' ? 'index' : route } .${ isAppPage && ! dataRoute ? 'body' : 'html' } `
1197+ `${ normalizePagePath ( route ) } .${ isAppPage && ! dataRoute ? 'body' : 'html' } `
11961198 )
11971199
11981200 // we use the static 404 for notFound: true if available
@@ -1268,7 +1270,7 @@ export async function handleBuildComplete({
12681270 if ( dataRoute ) {
12691271 let dataFilePath = path . join (
12701272 pagesDistDir ,
1271- `${ route === '/' ? 'index' : route } .json`
1273+ `${ normalizePagePath ( route ) } .json`
12721274 )
12731275
12741276 if ( isAppPage ) {
@@ -1593,16 +1595,18 @@ export async function handleBuildComplete({
15931595 prefixRouteKeys : true ,
15941596 includeSuffix : true ,
15951597 } )
1598+ const isDataRoute = dataRoutePages . has ( page )
1599+
15961600 const destination = path . posix . join (
15971601 '/' ,
15981602 config . basePath ,
1599- ...( dataRoutePages . has ( page ) ? [ `_next/data` , buildId ] : '' ) ,
1603+ ...( isDataRoute ? [ `_next/data` , buildId ] : '' ) ,
16001604 ...( page === '/'
16011605 ? [ shouldLocalize ? '$nextLocale.json' : 'index.json' ]
16021606 : [
16031607 shouldLocalize ? '$nextLocale' : '' ,
16041608 page +
1605- '.json' +
1609+ ( isDataRoute ? '.json' : '' ) +
16061610 getDestinationQuery ( routeRegex . routeKeys || { } ) ,
16071611 ] )
16081612 )
0 commit comments