Fix dynamic default locale routing

This commit is contained in:
MOH
2026-03-15 04:41:08 +01:00
parent 50c3f5cce9
commit 364f761420
13 changed files with 73 additions and 32 deletions
+10 -3
View File
@@ -5,7 +5,7 @@ import { isRedirectError } from "next/dist/client/components/redirect-error";
import { z } from "zod";
import { enforceContactRateLimit, verifyTurnstileToken } from "@/lib/contact-guard";
import { getContactProtectionSettings } from "@/lib/app-config";
import { getContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
import { sendContactMessage } from "@/lib/mail";
@@ -60,7 +60,8 @@ function getStringValue(formData: FormData, key: string) {
export async function submitContactFormAction(formData: FormData) {
const locale = resolveLocale(String(formData.get("locale") ?? ""));
const contactPath = getLocalizedPath(locale, "/contact");
const siteSettings = await getSiteSettings();
const contactPath = getLocalizedPath(locale, "/contact", siteSettings.defaultLocale);
try {
const protectionSettings = await getContactProtectionSettings();
@@ -86,7 +87,13 @@ export async function submitContactFormAction(formData: FormData) {
message: values.message,
});
redirect(withMessage(getLocalizedPath(locale, "/success"), "success", contactSuccessMessages[locale]));
redirect(
withMessage(
getLocalizedPath(locale, "/success", siteSettings.defaultLocale),
"success",
contactSuccessMessages[locale],
),
);
} catch (error) {
if (isRedirectError(error)) {
throw error;
+4 -3
View File
@@ -7,7 +7,7 @@ import { PageHero } from "@/components/layout/page-hero";
import { MotionFade } from "@/components/motion-fade";
import { ContactForm } from "@/components/site/contact-form";
import { buildLocalizedMetadata } from "@/lib/metadata";
import { getPublicContactProtectionSettings } from "@/lib/app-config";
import { getPublicContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
import { AppCard } from "@/components/ui/app-card";
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@@ -36,9 +36,10 @@ export async function generateMetadata({ params }: ContactPageProps): Promise<Me
export default async function ContactPage({ params }: ContactPageProps) {
const { locale } = await params;
const localeKey = resolveLocale(locale);
const [t, protection] = await Promise.all([
const [t, protection, siteSettings] = await Promise.all([
getTranslations({ locale: localeKey, namespace: "contactPage" }),
getPublicContactProtectionSettings(),
getSiteSettings(),
]);
return (
@@ -82,7 +83,7 @@ export default async function ContactPage({ params }: ContactPageProps) {
<ContactForm
action={submitContactFormAction}
locale={localeKey}
previewHref={getLocalizedPath(localeKey, "/success")}
previewHref={getLocalizedPath(localeKey, "/success", siteSettings.defaultLocale)}
protection={protection}
copy={{
name: t("name"),