Skip to content

Commit 3a975a7

Browse files
committed
fix(core): skip BC route resolution for 404 path
1 parent 06fd9aa commit 3a975a7

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { notFound } from 'next/navigation';
22

33
export default function CatchAllPage() {
4+
console.log('CatchAllPage CALLED');
45
notFound();
56
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { notFound } from 'next/navigation';
2+
3+
export default function NotFoundHandler() {
4+
console.log('NotFoundHandler CALLED');
5+
notFound();
6+
}

core/middlewares/with-routes.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,23 @@ const getRouteInfo = async (request: NextRequest, event: NextFetchEvent) => {
288288
export const withRoutes: MiddlewareFactory = () => {
289289
// eslint-disable-next-line complexity
290290
return async (request, event) => {
291+
// eslint-disable-next-line no-console
292+
console.log('withRoutes CALLED', request.url);
293+
291294
const locale = request.headers.get('x-bc-locale') ?? '';
292295

296+
// Handle /404 path - rewrite to valid route that calls notFound()
297+
const pathWithoutLocale = clearLocaleFromPath(request.nextUrl.pathname, locale);
298+
299+
if (pathWithoutLocale === '/404' || pathWithoutLocale === '/404/') {
300+
console.log('404 path found, rewriting to not-found-handler', locale);
301+
302+
return NextResponse.rewrite(
303+
304+
new URL(`/${locale}/not-found-handler${request.nextUrl.search}`, request.url),
305+
);
306+
}
307+
293308
const { route, status } = await getRouteInfo(request, event);
294309

295310
if (status === 'MAINTENANCE') {
@@ -411,6 +426,8 @@ export const withRoutes: MiddlewareFactory = () => {
411426
}
412427
}
413428

429+
console.log('middlewareurl', url);
430+
414431
const rewriteUrl = new URL(url, request.url);
415432

416433
rewriteUrl.search = request.nextUrl.search;

0 commit comments

Comments
 (0)