Skip to content

Commit 8389145

Browse files
committed
fix: skip BC route resolution for 404 path
1 parent 8096cc5 commit 8389145

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

core/middlewares/with-routes.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)