Do not use redirects inside a loader, as loaders only execute during the build process for data fetching. To perform a redirect, use a component with useNavigate from react-router-dom inside a useEffect hook.
import { useNavigate } from 'react-router-dom'
import { useEffect } from 'react'
// Inside your routes definition
{
path: '/',
Component: () => {
const navigate = useNavigate()
useEffect(() => {
navigate('/en', { replace: true })
}, [navigate])
return null
},
}
export const routes: RouteRecord[] = [
{
path: '/:lng',
Component: Layout,
getStaticPaths: () => Object.keys(resources),
children: [
// ... some routes
],
},
{
path: '/',
Component: () => {
const navigate = useNavigate()
useEffect(() => {
navigate('/en', { replace: true })
}, [navigate])
return null
},
},
]