redirect is ignoring localePrefix "as-needed" option #1182
-
I made a setup like this following the docs // src/config.ts
import type { LocalePrefix } from "next-intl/routing";
export const locales = ["en", "tr"] as const;
export const localePrefix = "as-needed" satisfies LocalePrefix; // src/middleware.ts
import createMiddleware from "next-intl/middleware";
import { localePrefix, locales } from "./config";
export default createMiddleware({
locales,
defaultLocale: "tr",
localePrefix,
localeDetection: false,
});
export const config = {
matcher: [
"/((?!api|_next|_vercel|.*\\..*).*)",
],
}; // src/i18n.ts
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
import { locales } from "./config";
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as typeof locales[0])) notFound();
return {
messages: (await import(`../dictionaries/${locale}.json`)).default,
};
}); // src/navigation.ts
import { createSharedPathnamesNavigation } from "next-intl/navigation";
import { locales } from "./config";
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation({ locales }); Everything works as expected. But when I'm redirected from a server action, it includes locale prefix (default) to the url: // src/actions/session.ts
"use server";
import { getSession } from "~/core/session";
import { redirect } from "~/navigation";
export async function logout() {
const session = await getSession();
session.userId = undefined;
await session.save();
redirect("/login");
} Am I doing something wrong? or is this how it works? |
Beta Was this translation helpful? Give feedback.
Answered by
amannn
Jul 10, 2024
Replies: 1 comment
-
It's indeed how this is implemented currently, but an improved behavior is coming in #444! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
omermecitoglu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's indeed how this is implemented currently, but an improved behavior is coming in #444!