Files
ipd-shomalhospital-frontend/src/middleware.js
2026-03-26 08:09:01 +03:30

31 lines
678 B
JavaScript

import { NextResponse } from "next/server";
const DEFAULT_LOCALE = "fa"; // fallback امن
export function middleware(request) {
const { pathname } = request.nextUrl;
if (
pathname.startsWith("/_next") ||
pathname.startsWith("/api") ||
pathname.match(/\.(.*)$/)
) {
return NextResponse.next();
}
const segments = pathname.split("/");
const maybeLang = segments[1];
// فقط چک کن آیا prefix داره یا نه
if (!maybeLang) {
return NextResponse.redirect(
new URL(`/${DEFAULT_LOCALE}${pathname}`, request.url)
);
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!_next|.*\\..*).*)"],
};