is there any way to switch language in nextjs without passing language parameter in url like baseurl/ar or baseurl/en ? if I want to change language from dropdown, url should not change.
language change in nextjs without changing url
Asked Answered
If you're using Next.js i18n routing, the locale is required in the URL (for non-default locales). You could implement your own i18n routing solution if you don't want that behaviour. –
Provide
You need to import Link from next/link, and get the router instance from useRouter, or withRouter hoc. Usage:
<Link href={router.pathname} locale='your language'/>
Should work fine!
query parameters are defined by the routes of your api, in this way, when you change the url, a new call is made in the api passing the parameters that were informed in the route.
you can pass objects to the api route, something like:
const response = awai api.get('yourUrl', {language: en})
this way the information will not appear in the url, but this needs to be changed in the backend so that it knows where to get the parameters from.
- you can choose to do the translation in json files, and just switch between them too.
Hope this helps.
#NSL
This answer doesn't address the issue on the question. –
Lover
© 2022 - 2025 — McMap. All rights reserved.