Skip to content

Commit 8001f8b

Browse files
committed
fix(docs): use window.location.replace for reliable language redirect
Replace router.go() with window.location.replace() for browser language auto-detection redirect. This ensures more reliable redirection without relying on VitePress client-side routing, and prevents the language selection page from briefly flashing before redirect.
1 parent 2aae299 commit 8001f8b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

docs/index.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,23 @@ hero:
1515

1616
<script setup>
1717
import { onBeforeMount } from 'vue'
18-
import { useRouter } from 'vitepress'
1918

2019
// Client-only execution for SSR compatibility
2120
onBeforeMount(() => {
2221
if (typeof window === 'undefined') return
23-
24-
const router = useRouter()
22+
2523
const userLang = navigator.language || navigator.userLanguage || ''
2624
const savedLang = localStorage.getItem('docs-lang-preference')
27-
25+
2826
// Use saved preference if exists, otherwise use browser language
2927
const targetLang = savedLang || (userLang.startsWith('zh') ? '/zh/' : '/en/')
3028
const currentPath = window.location.pathname
31-
29+
3230
// Only redirect if not already on correct language path
3331
if (targetLang === '/zh/' && !currentPath.startsWith('/zh')) {
34-
router.go('/zh/')
32+
window.location.replace('/zh/')
3533
} else if (targetLang === '/en/' && !currentPath.startsWith('/en')) {
36-
router.go('/en/')
34+
window.location.replace('/en/')
3735
}
3836
})
3937
</script>

0 commit comments

Comments
 (0)