File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
packages/runtime/src/helpers Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,33 @@ const generateLocaleRedirects = ({
56
56
return redirects
57
57
}
58
58
59
+ const generateCustom404Redirects = ( { i18n } : Pick < NextConfig , 'i18n' > ) : NetlifyConfig [ 'redirects' ] => {
60
+ const redirects : NetlifyConfig [ 'redirects' ] = [ ]
61
+
62
+ if ( i18n ) {
63
+ i18n . locales . forEach ( ( locale ) => {
64
+ redirects . push ( {
65
+ from : `/${ locale } /*` ,
66
+ to : `/server/pages/${ locale } /404.html` ,
67
+ status : 404 ,
68
+ } )
69
+ } )
70
+ redirects . push ( {
71
+ from : '/*' ,
72
+ to : `/server/pages/${ i18n . defaultLocale } /404.html` ,
73
+ status : 404 ,
74
+ } )
75
+ } else {
76
+ redirects . push ( {
77
+ from : '/*' ,
78
+ to : '/server/pages/404.html' ,
79
+ status : 404 ,
80
+ } )
81
+ }
82
+
83
+ return redirects
84
+ }
85
+
59
86
export const generateStaticRedirects = ( {
60
87
netlifyConfig,
61
88
nextConfig : { i18n, basePath } ,
@@ -245,6 +272,8 @@ export const generateRedirects = async ({
245
272
netlifyConfig . redirects . push ( ...generateLocaleRedirects ( { i18n, basePath, trailingSlash } ) )
246
273
}
247
274
275
+ netlifyConfig . redirects . push ( ...generateCustom404Redirects ( { i18n } ) )
276
+
248
277
// This is only used in prod, so dev uses `next dev` directly
249
278
netlifyConfig . redirects . push (
250
279
// API routes always need to be served from the regular function
You can’t perform that action at this time.
0 commit comments