This commit is contained in:
parent
138daa7458
commit
f357049048
|
|
@ -4,6 +4,13 @@ import { useEffect } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import i18nConfig from '@/i18nConfig'
|
import i18nConfig from '@/i18nConfig'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const isValidLocale = (locale: string): locale is (typeof i18nConfig.locales)[number] => {
|
||||||
|
return (i18nConfig.locales as readonly string[]).includes(locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function HomeRedirector() {
|
export default function HomeRedirector() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
|
@ -13,13 +20,13 @@ export default function HomeRedirector() {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
preferred &&
|
preferred &&
|
||||||
(i18nConfig.locales as string[]).includes(preferred) &&
|
isValidLocale(preferred) &&
|
||||||
!currentPath.startsWith(`/${preferred}/`)
|
!currentPath.startsWith(`/${preferred}/`)
|
||||||
) {
|
) {
|
||||||
const newPath = `/${preferred}${currentPath}`
|
const newPath = `/${preferred}${currentPath}`
|
||||||
router.replace(newPath)
|
router.replace(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue