From 594995f320430afd4a46ce929a67e048d9af1542 Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Thu, 27 Nov 2025 11:18:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(js=E5=85=A5=E5=8F=A3=E6=96=87=E4=BB=B6):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=88=90=E5=93=88=E5=B8=8C=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index e8ce073..be54255 100644 --- a/src/main.js +++ b/src/main.js @@ -34,10 +34,6 @@ app.use(pinia) // 获取 langStore 并传递给 initI18n const langStore = useLangStore() // 直接使用 import 的函数 -// 检测URL参数并设置语言 -const urlParams = new URLSearchParams(window.location.search) -const langParam = urlParams.get('lang') - //排行榜 const RankingPage = [ '/top-list', //排行榜 @@ -58,7 +54,13 @@ const enPages = [...RankingPage, ...ACTIVITIES] const arPages = [] // 获取当前页面路径 -const currentPage = window.location.pathname +const hashPath = window.location.hash.replace('#', '') +const currentPage = hashPath.split('?')[0] // 提取纯路径部分,去除查询参数 + +// 检测URL参数并设置语言 +const queryParams = hashPath.split('?')[1] +const urlParams = queryParams ? new URLSearchParams(queryParams) : new URLSearchParams() +const langParam = urlParams.get('lang') // 检查当前页面是否在固定英语的页面列表中 if (enPages.includes(currentPage)) { @@ -72,6 +74,8 @@ else if (arPages.includes(currentPage)) { } // 对于其他页面,如果有URL参数则按参数设置语言 else if (langParam) { + console.log('langParam:', langParam) + setLocale(langStore, langParam) }