File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff 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 ( / ^ \/ e n \/ / , "/" ) ;
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
You can’t perform that action at this time.
0 commit comments