Next.js Discord

Discord Forum

router.push() with dynamic secment

Answered
Alapaha Blue Blood Bulldog posted this in #help-forum
Open in Discord
Alapaha Blue Blood BulldogOP
Hello! I'm following this tutorial to make my app multilingual: https://locize.com/blog/next-app-dir-i18n/

So basically I add a dynamic segment with this structure: app/[lng]/page.tsx

It seems to work but I have 1 issue. When I use the router.push(/en/) in another page to navigate back to the home page after submitting a form it will throw an error as seen on the image. When I will refresh the same page it will start working again. Any idea what I might be doing wrong_
Answered by Alapaha Blue Blood Bulldog
Found the solution. ${encodeURIComponent(params.lng.toString())} seems to be working.
View full answer

1 Reply

Alapaha Blue Blood BulldogOP
Found the solution. ${encodeURIComponent(params.lng.toString())} seems to be working.
Answer