@@ -783,7 +783,39 @@ async function exportAppImpl(
783
783
Object . keys ( prerenderManifest . routes ) . map ( async ( unnormalizedRoute ) => {
784
784
// Special handling: map app /_not-found to 404.html (and 404/index.html when trailingSlash)
785
785
if ( unnormalizedRoute === '/_not-found' ) {
786
- return
786
+ const { srcRoute } = prerenderManifest ! . routes [ unnormalizedRoute ]
787
+ const appPageName = mapAppRouteToPage . get ( srcRoute || '' )
788
+ const pageName = appPageName || srcRoute || unnormalizedRoute
789
+ const isAppPath = Boolean ( appPageName )
790
+ const route = normalizePagePath ( unnormalizedRoute )
791
+
792
+ const pagePath = getPagePath ( pageName , distDir , undefined , isAppPath )
793
+ const distPagesDir = join (
794
+ pagePath ,
795
+ pageName
796
+ . slice ( 1 )
797
+ . split ( '/' )
798
+ . map ( ( ) => '..' )
799
+ . join ( '/' )
800
+ )
801
+
802
+ const orig = join ( distPagesDir , route )
803
+ const htmlSrc = `${ orig } .html`
804
+
805
+ // write 404.html at root
806
+ const htmlDest404 = join ( outDir , '404.html' )
807
+ await fs . mkdir ( dirname ( htmlDest404 ) , { recursive : true } )
808
+ await fs . copyFile ( htmlSrc , htmlDest404 )
809
+
810
+ // When trailingSlash, also write 404/index.html
811
+ if ( subFolders ) {
812
+ const htmlDest404Index = join ( outDir , '404' , 'index.html' )
813
+ await fs . mkdir ( dirname ( htmlDest404Index ) , { recursive : true } )
814
+ await fs . copyFile ( htmlSrc , htmlDest404Index )
815
+ }
816
+ if ( ! options . buildExport ) {
817
+ await fs . rm ( htmlSrc )
818
+ }
787
819
}
788
820
// Skip 500.html in static export
789
821
if ( unnormalizedRoute === '/_global-error' ) {
0 commit comments