QuiiBz / next-international

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

Pages-dir and App-dir can't work together #133

Closed aulonm closed 1 year ago

aulonm commented 1 year ago

Hi,

Thanks for the amazing DX on next-international, and all the help you have been providing!

We are in a middle of a migration from pages to app-dir and need them both to colocate since its a fairly big application and it takes time to migrate 100% over to app-dir.

The repro: https://github.com/aulonm/next-international-repro (updated it with this issue)

The problem we are facing now is when we add [locale] folder to the app-folder, and next.config has the i18n-object (this is needed for pages-dir).

The routing doesn't work as expected.

App-dir has the following routes:

Pages dir has the following routes:

When running the dev-server and navigating to /ssr-ssg it returns the pages-dir, which is correct. When navigating to /client it returns the root-file in app-dir and I can't get access to the subpages withouth doing something like /en/subpage or /en/client (the client one doesn't work).

Is this a limitation in the package or something that I'm missing?

QuiiBz commented 1 year ago

That might be related to https://github.com/vercel/next.js/issues/47430 - removing the i18n config inside next.config.js resolves the issue for the App dir, but (as expected) breaks the Pages Dir.

aulonm commented 1 year ago

If I read that issue correct, shouldn't next-international change to check the request.url.pathname and not request.nextUrl.pathname for the locale or would that be the wrong way fo doing this?

Edit: We've decided to just go with a big rewrite to move over to app-dir for the whole application. Thanks for all the help!

QuiiBz commented 1 year ago

I've tried with url instead of nextUrl but the same issue persists - I really think this is due to some strange things inside Next.js when you use both App and Pages router with i18n inside next.config.js.

We've decided to just go with a big rewrite to move over to app-dir for the whole application. Thanks for all the help!

That's probably the "easiest" way to solve this issue. Thanks and let me know if you have any other question!