mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-07 15:10:32 +00:00
fix: language switching now strictly follows URL path
- Remove localStorage dependency for language persistence - Add route change listener for language updates - Simplify language switching logic - Fix language reset issue when refreshing /en pages
This commit is contained in:
@@ -87,9 +87,35 @@ export function GlobalContextProvider(props) {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加路由变化时的语言处理
|
||||
useEffect(() => {
|
||||
const handleRouteChange = (url) => {
|
||||
// 从路径中提取语言前缀
|
||||
const pathSegments = url.split('/')
|
||||
const pathLang = pathSegments[1]
|
||||
|
||||
// 检查是否是有效的语言路径
|
||||
if (pathLang === 'en' || pathLang === 'zh') {
|
||||
const targetLang = pathLang === 'en' ? 'en-US' : 'zh-CN'
|
||||
|
||||
// 直接更新语言,不使用 localStorage
|
||||
updateLang(targetLang)
|
||||
updateLocale(generateLocaleDict(targetLang))
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化时处理当前路径
|
||||
handleRouteChange(router.asPath)
|
||||
|
||||
// 监听路由变化
|
||||
router.events.on('routeChangeComplete', handleRouteChange)
|
||||
return () => {
|
||||
router.events.off('routeChangeComplete', handleRouteChange)
|
||||
}
|
||||
}, [router])
|
||||
|
||||
useEffect(() => {
|
||||
initDarkMode(updateDarkMode, defaultDarkMode)
|
||||
initLocale(lang, locale, updateLang, updateLocale)
|
||||
if (
|
||||
NOTION_CONFIG?.REDIRECT_LANG &&
|
||||
JSON.parse(NOTION_CONFIG?.REDIRECT_LANG)
|
||||
|
||||
Reference in New Issue
Block a user