Migrating from page router with dynamic root level and i18n to app router #62398
Replies: 2 comments
-
|
Would love to hear something about that, since we also struggle to migrate to AppRouter with this issue. |
Beta Was this translation helpful? Give feedback.
-
|
Yes, this is a real and well-known constraint during Next.js App Router migrations, and progressive migration is absolutely possible — but it requires a specific structural approach to resolve the Why the clash happensNext.js resolves routes by matching the file system structure across both Both are top-level dynamic segments. Next.js cannot distinguish between them at routing time — a request to The correct solution — wrap everything under a
|
| Rule | Why |
|---|---|
Remove a route from pages/ when you add it to app/ |
Same URL cannot be in both routers simultaneously |
Use static segments in app/ for migrated categories |
Static beats dynamic — /products in app/ wins over [category] in pages/ |
Keep next.config.js i18n config active until all pages are migrated |
Pages Router needs it; App Router uses [lang] segment instead |
Use NextResponse.rewrite in middleware, not redirect |
Rewrite preserves URLs for SEO; redirect changes the URL |
Don't use [[...slug]] at the top level of app/ while pages/[category] exists |
Optional catch-all would conflict with every pages/ dynamic route |
Progressive migration is entirely supported and this approach is exactly how the Next.js team recommends doing it. You don't need to migrate everything at once.
Hope this helps — if it answers your question, would you mind clicking "Mark as answer" so others searching for the same thing can find it quickly?
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi guys, I'm having a hard time trying to convert my site to use the app router.
Most of my pages are under a dynamic root, ie
pages/[category]/..., and I also have support for i18n routing, so the following route is also possible:https://example.com/[lang]/[category]/rest.Now, afaik, when using app router, to support i18n we should add a root dynamic route like:
app/[lang]and this is where it clashes with my pages. I can't have bothpages/[category]andapp/[lang]as it makes Next not know where to route.So, my question is: Is there a way to migrate my site without having to migrate all my pages all at once? I really wanted to make a progressive transition, only migrating a few pages and componentes at a time.
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions