1

I want to do three things in my application, but I’m not figuring out how I could do that using Next.js router.

  1. The default URL of the application should be 'https://localhost:3000/en'
  2. It should also be possible to have 'https://localhost:3000/es' as a valid URL
  3. Anything different than '/es' should redirect to '/en'

(This parameter will influence on the displayed language of the application.)

Considering those three points, should I create inside pages folder a new folder called language and put my index.tsx file and all the others routes that I have?

Example here

If I do that, what are the rules that I should create on my next.config.js to match with the criteria that I listed above? If not, what could be another approach to solve this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I'd recommend looking into Next.js [i18n routing](https://nextjs.org/docs/advanced-features/i18n-routing). You could then use the approach suggested in [How to enforce i18n locale slugs and achieve i18n consistency upon reload in Next.js?](https://stackoverflow.com/questions/67149545/how-to-enforce-i18n-locale-slugs-and-achieve-i18n-consistency-upon-reload-in-nex) to force the locale prefix on all pages. – juliomalves Sep 26 '22 at 07:48

0 Answers0