I am attempting to switch the locale by connecting the onClick
event to two separate <div>
elements:
import { useRouter } from 'next/router'
// other codes
const router = useRouter()
const changeLocale = (locale) => {
router.push({
router: router.pathname,
query: router.query
}, router.asPath, { locale })
}
return <div>
<div onClick={() => changeLocale('en')}>EN</div>
<div onClick={() => changeLocale('ru')}>RU</div>
</div>
The issue I'm facing is that the URL is not updating. For example, when I am at /en/about
and click on the "RU" option, the URL remains as /en/about
.
I would like to understand why the router.push
function is not behaving as expected in this scenario.