@@ -72,9 +72,18 @@ export const netlifyRoutesForNextRouteWithData = ({ route, dataRoute }: { route:
72
72
export const routeToDataRoute = ( route : string , buildId : string , locale ?: string ) =>
73
73
`/_next/data/${ buildId } ${ locale ? `/${ locale } ` : '' } ${ route === '/' ? '/index' : route } .json`
74
74
75
- const netlifyRoutesForNextRoute = ( route : string , buildId : string , i18n ?: I18n ) : Array < string > => {
75
+ const netlifyRoutesForNextRoute = (
76
+ route : string ,
77
+ buildId : string ,
78
+ i18n ?: I18n ,
79
+ ) : Array < { redirect : string ; locale : string | false } > => {
76
80
if ( ! i18n ?. locales ?. length ) {
77
- return netlifyRoutesForNextRouteWithData ( { route, dataRoute : routeToDataRoute ( route , buildId ) } )
81
+ return netlifyRoutesForNextRouteWithData ( { route, dataRoute : routeToDataRoute ( route , buildId ) } ) . map (
82
+ ( redirect ) => ( {
83
+ redirect,
84
+ locale : false ,
85
+ } ) ,
86
+ )
78
87
}
79
88
const { locales, defaultLocale } = i18n
80
89
const routes = [ ]
@@ -87,7 +96,10 @@ const netlifyRoutesForNextRoute = (route: string, buildId: string, i18n?: I18n):
87
96
...netlifyRoutesForNextRouteWithData ( {
88
97
route : locale === defaultLocale ? route : `/${ locale } ${ route } ` ,
89
98
dataRoute,
90
- } ) ,
99
+ } ) . map ( ( redirect ) => ( {
100
+ redirect,
101
+ locale,
102
+ } ) ) ,
91
103
)
92
104
} )
93
105
return routes
@@ -115,13 +127,33 @@ export const redirectsForNextRoute = ({
115
127
status ?: number
116
128
force ?: boolean
117
129
} ) : NetlifyConfig [ 'redirects' ] =>
118
- netlifyRoutesForNextRoute ( route , buildId , i18n ) . map ( ( redirect ) => ( {
130
+ netlifyRoutesForNextRoute ( route , buildId , i18n ) . map ( ( { redirect } ) => ( {
119
131
from : `${ basePath } ${ redirect } ` ,
120
132
to,
121
133
status,
122
134
force,
123
135
} ) )
124
136
137
+ export const redirectsForNext404Route = ( {
138
+ route,
139
+ buildId,
140
+ basePath,
141
+ i18n,
142
+ force = false ,
143
+ } : {
144
+ route : string
145
+ buildId : string
146
+ basePath : string
147
+ i18n : I18n
148
+ force ?: boolean
149
+ } ) : NetlifyConfig [ 'redirects' ] =>
150
+ netlifyRoutesForNextRoute ( route , buildId , i18n ) . map ( ( { redirect, locale } ) => ( {
151
+ from : `${ basePath } ${ redirect } ` ,
152
+ to : locale ? `${ basePath } /server/pages/${ locale } /404.html` : `${ basePath } /server/pages/404.html` ,
153
+ status : 404 ,
154
+ force,
155
+ } ) )
156
+
125
157
export const redirectsForNextRouteWithData = ( {
126
158
route,
127
159
dataRoute,
0 commit comments