Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
513dcb7fea |
+34
-2
@@ -1,9 +1,41 @@
|
|||||||
import createMiddleware from "next-intl/middleware";
|
import createMiddleware from "next-intl/middleware";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import type { NextRequest } from "next/server";
|
||||||
import { routing } from "./src/i18n/routing";
|
import { routing } from "./src/i18n/routing";
|
||||||
|
|
||||||
export default createMiddleware({
|
const oldSerbianPaths = ["", "products", "about", "contact", "checkout"];
|
||||||
|
|
||||||
|
export default function middleware(request: NextRequest) {
|
||||||
|
const pathname = request.nextUrl.pathname;
|
||||||
|
|
||||||
|
const isOldSerbianPath = oldSerbianPaths.some((path) => {
|
||||||
|
if (path === "") {
|
||||||
|
return pathname === "/";
|
||||||
|
}
|
||||||
|
return pathname === `/${path}` || pathname.startsWith(`/${path}/`);
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasLocalePrefix = routing.locales.some(
|
||||||
|
(locale) => pathname === `/${locale}` || pathname.startsWith(`/${locale}/`)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isOldSerbianPath && !hasLocalePrefix) {
|
||||||
|
const newPathname = pathname === "/"
|
||||||
|
? "/sr"
|
||||||
|
: `/sr${pathname}`;
|
||||||
|
|
||||||
|
const url = request.nextUrl.clone();
|
||||||
|
url.pathname = newPathname;
|
||||||
|
|
||||||
|
return NextResponse.redirect(url, 301);
|
||||||
|
}
|
||||||
|
|
||||||
|
const intlMiddleware = createMiddleware({
|
||||||
...routing,
|
...routing,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return intlMiddleware(request);
|
||||||
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: [
|
||||||
|
|||||||
Reference in New Issue
Block a user