Next.js Discord

Discord Forum

NextJS 16.0 ./i18n/routing not working with filename proxy.ts?

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Hello,
i tried to upgrade to Next16 everything works fine. One point, the middleware.ts will be changed to proxy shortly so i would like to rename it to.
But my side is just working with middleware.ts. when i rename to proxy.ts i always receive 404 in release build and started with npm run start. When i type localhost:3000/en, it works on the home page, but the router is not working, whenever i click on any page I receive 404 again. When i type localhost:3000/en/contact. It works!

My middleware.ts or renamed to proxy.ts

// src/proxy.ts
import createMiddleware from "next-intl/middleware";
import { NextResponse, NextRequest } from "next/server";
import { routing } from "./i18n/routing";

const intlProxy = createMiddleware(routing);

export default function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;

// Root -> intern auf Default-Locale umschreiben (URL bleibt "/")
if (pathname === "/") {
const url = request.nextUrl.clone();
url.pathname = /${routing.defaultLocale};
return NextResponse.rewrite(url);
// Falls du sichtbaren Redirect willst: return NextResponse.redirect(url);
}

// sonst normal über next-intl laufen lassen
return intlProxy(request);
}

export const config = {
matcher: ["/", "/((?!api|_next|_vercel|.\..).*)"],
};

0 Replies