'query is empty when language is change using setAppLanguage in nextjs
I'm using Nextjs, and when I redirect to a page(pages/search/index), I can get the query in getServerSideProps but when I change the language using setAppLanguage by importing it from next-translate/setLanguage, the search page is reloaded again but the query is empty in getServerSideProps and I request with an empty query inside this page. By the way, the URL is updated from http://localhost:3000/tr/search?q=anything to http://localhost:3000/en/search?q=anything after the language is changed
Solution 1:[1]
It helped me
const router = useRouter()
const changeLanguage = (lang: string) => async () => {
await router.push(router.asPath, undefined, {
locale: lang
})
}
used it instead of setLanguage
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mike Glyancev |
