File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -290,6 +290,19 @@ export const withRoutes: MiddlewareFactory = () => {
290290 return async ( request , event ) => {
291291 const locale = request . headers . get ( 'x-bc-locale' ) ?? '' ;
292292
293+ const { pathname } = new URL ( request . url ) ;
294+ const cleanPathName = clearLocaleFromPath ( pathname , locale ) ;
295+
296+ // This path should be handled by Next.js's not-found page via the catch-all route
297+ if ( cleanPathName === '/404' || cleanPathName === '/404/' ) {
298+ // Avoid redeclaring rewriteUrl if already declared in upper scope
299+ const url404 = new URL ( `/${ locale } /404` , request . url ) ;
300+
301+ url404 . search = request . nextUrl . search ;
302+
303+ return NextResponse . rewrite ( url404 ) ;
304+ }
305+
293306 const { route, status } = await getRouteInfo ( request , event ) ;
294307
295308 if ( status === 'MAINTENANCE' ) {
@@ -403,10 +416,6 @@ export const withRoutes: MiddlewareFactory = () => {
403416 }
404417
405418 default : {
406- const { pathname } = new URL ( request . url ) ;
407-
408- const cleanPathName = clearLocaleFromPath ( pathname , locale ) ;
409-
410419 url = `/${ locale } ${ cleanPathName } ` ;
411420 }
412421 }
You can’t perform that action at this time.
0 commit comments