QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.25k stars 59 forks source link

`basePath` does not work with `urlMappingStrategy: "rewrite"` in `app` router #248

Open setowilliam opened 10 months ago

setowilliam commented 10 months ago

Describe the bug When using the next-app example, using basePath with urlMappingStrategy: "rewrite" redirects to not-found page when navigating to http://localhost:3000/base.

To Reproduce Steps to reproduce the behavior:

  1. Set basePath in locales/client.ts to /base
  2. Set basePath in next.config.js to /base
  3. Set urlMappingStrategy in middleware.ts to rewrite
  4. Start dev server
  5. Go to http://localhost:3000/base
  6. not-found screen is shown

Expected behavior From the description of rewrite:

rewrite: https://example.com/products -> rewrite to https://example.com/en/products -> client doesn't see the locale in the url

I would expect that navigating to http://localhost:3000/base would rewrite to http://localhost:3000/base/en.

Screenshots Screenshot 2023-10-16 at 11 37 20

About (please complete the following information):

QuiiBz commented 10 months ago

Good catch, we'll probably need to introduce a new basePath option to createI18nMiddleware. In the meantime, you could use the default urlMappingStrategy. Not ideal but I'll try to fix this bug asap.

yukiyohure commented 4 months ago

@QuiiBz I came across the same Issue. I believe this library is one of the few libraries that meet the need for the Next.js app router users to "do not want to change the url structure by introducing i18n feature into our app". So I hope this Issue will be fixed as soon as possible.