fix(js入口文件): 修复获取不到语言参数的问题,设置成哈希路由的参数获取方式

This commit is contained in:
hzj 2025-11-27 11:18:54 +08:00
parent ef07c5056e
commit 594995f320

View File

@ -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)
}