Fix landing locale toggle cache path

This commit is contained in:
2569718930@qq.com
2026-06-14 05:11:37 +08:00
parent b4a23578f2
commit 0084235b57
5 changed files with 38 additions and 12 deletions
@@ -1,9 +1,8 @@
"use client";
import { useTransition } from "react";
import { useRouter } from "next/navigation";
import {
LANDING_LOCALE_COOKIE,
LANDING_LOCALE_QUERY_PARAM,
nextLandingLocale,
type LandingLocale,
} from "@/components/landing/landingLocale";
@@ -11,8 +10,6 @@ import {
const ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
export function LandingLocaleToggle({ locale }: { locale: LandingLocale }) {
const router = useRouter();
const [isPending, startTransition] = useTransition();
const isEn = locale === "en-US";
const toggleLocale = () => {
@@ -24,16 +21,16 @@ export function LandingLocaleToggle({ locale }: { locale: LandingLocale }) {
} catch {
// Locale persistence is best-effort; the cookie is enough for SSR.
}
startTransition(() => {
router.refresh();
});
const url = new URL(window.location.href);
url.searchParams.set(LANDING_LOCALE_QUERY_PARAM, nextLocale);
window.location.assign(url.toString());
};
return (
<button
type="button"
onClick={toggleLocale}
disabled={isPending}
className="inline-flex h-9 cursor-pointer items-center gap-1 rounded-md border border-slate-200 bg-white px-1 text-xs font-semibold text-slate-500 shadow-sm hover:border-slate-300 disabled:cursor-wait disabled:opacity-70"
aria-label={isEn ? "Switch language" : "切换语言"}
>