Skip to content

Commit e7551ff

Browse files
committed
a
1 parent 9a8697f commit e7551ff

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/theme/Root/index.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ function detectAndRedirectLanguage() {
1010
// 标记已执行重定向
1111
localStorage.setItem("redirected", "true");
1212

13-
// 检查是否已经在英文路径下
14-
if (window.location.pathname.startsWith("/en/")) {
15-
return;
16-
}
17-
1813
// 获取用户首选语言
1914
const userLanguages = navigator.languages || [navigator.language];
2015

@@ -43,6 +38,20 @@ function detectAndRedirectLanguage() {
4338

4439
// 跳转到英文版本
4540
window.location.href = fullPath;
41+
} else {
42+
// 中文用户重定向到默认中文路径
43+
if (window.location.pathname.startsWith("/en/")) {
44+
// 如果当前路径是英文版本,重定向到中文版本
45+
const currentPath = window.location.pathname.replace(/^\/en\//, "/");
46+
const search = window.location.search;
47+
const hash = window.location.hash;
48+
49+
// 构建中文版本的路径
50+
const chinesePath = currentPath + search + hash;
51+
52+
// 跳转到中文版本
53+
window.location.href = chinesePath;
54+
}
4655
}
4756
}
4857

0 commit comments

Comments
 (0)