27 lines
604 B
TypeScript
27 lines
604 B
TypeScript
'use client'
|
|
|
|
import { useEffect } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import i18nConfig from '@/i18nConfig'
|
|
|
|
export default function HomeRedirector() {
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
const preferred = localStorage.getItem('preferred-language')
|
|
const currentPath = window.location.pathname
|
|
|
|
if (
|
|
preferred &&
|
|
(i18nConfig.locales as string[]).includes(preferred) &&
|
|
!currentPath.startsWith(`/${preferred}/`)
|
|
) {
|
|
const newPath = `/${preferred}${currentPath}`
|
|
router.replace(newPath)
|
|
}
|
|
|
|
}, [])
|
|
|
|
return null
|
|
}
|