Skip to content

Let's use AI to Earn!

langa

bulaienaofutuojsonzhang6a2181828c10
diff --git a/src/app/i18n/client.ts b/src/app/i18n/client.ts
index 15abd1cc..4c714776 100644
--- a/src/app/i18n/client.ts
+++ b/src/app/i18n/client.ts
@@ -34,6 +34,9 @@ i18next
detection: {
order: ["path", "htmlTag", "cookie", "navigator"],
caches: ["cookie"], // 只缓存到 cookie,避免其他缓存干扰
+ // 禁用自动语言检测,完全依赖 URL 参数
+ lookupFromPathIndex: 0,
+ checkWhitelist: true,
},
preload: runsOnServerSide ? languages : [],
// 确保语言切换时立即生效
@@ -69,12 +72,15 @@ export function useTransClient<
useEffect(() => {
if (!lng) return;
- // 如果当前 i18next 语言与 URL 参数不同,强制切换
+ // 始终使用 URL 参数中的语言,忽略 i18next 的自动检测
if (i18next.resolvedLanguage !== lng) {
i18next.changeLanguage(lng).then(() => {
// 语言切换完成后,强制重新渲染
setActiveLng(lng);
});
+ } else {
+ // 即使语言相同,也确保状态同步
+ setActiveLng(lng);
}
}, [lng]);
diff --git a/src/app/layout/layoutNav.tsx b/src/app/layout/layoutNav.tsx
index 352f6233..26a0bbb0 100644
--- a/src/app/layout/layoutNav.tsx
+++ b/src/app/layout/layoutNav.tsx
@@ -229,8 +229,22 @@ function NavPE() {
// 确保使用当前语言前缀
const targetPath = e.key.startsWith('/') ? e.key : `/${e.key}`;
const fullPath = `/${lng}${targetPath}`;
- router.push(fullPath);
+
+ // 调试信息
+ console.log('Menu click debug:', {
+ key: e.key,
+ lng,
+ targetPath,
+ fullPath,
+ currentPath: window.location.pathname
+ });
+
+ // 先关闭菜单
setOpen(false);
+
+ // 使用 window.location.href 进行跳转,确保完全重新加载页面
+ // 这样可以避免路由状态混乱的问题
+ window.location.href = fullPath;
};
return (
diff --git a/src/hooks/useSystem.ts b/src/hooks/useSystem.ts
index c704e288..f28726c9 100644
--- a/src/hooks/useSystem.ts
+++ b/src/hooks/useSystem.ts
@@ -1,7 +1,14 @@
import { useParams } from "next/navigation";
-import { fallbackLng } from "@/app/i18n/settings";
+import { fallbackLng, languages } from "@/app/i18n/settings";
export function useGetClientLng() {
- const lng = useParams()?.lng || fallbackLng;
- return lng as string;
+ const params = useParams();
+ const lng = params?.lng;
+
+ // 确保返回的语言在支持的语言列表中
+ if (lng && languages.includes(lng as string)) {
+ return lng as string;
+ }
+
+ return fallbackLng;
}