Catch-all [...slug] at root conflicts with other dynamic routes and optional catch-all conflicts with root in Next.js App Router. #80747
Unanswered
guimeraalex020
asked this question in
App Router
Replies: 1 comment
-
I'm also confused about that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Catch-all
[...slug]
at root conflicts with other dynamic routes and optional catch-all conflicts with root in Next.js App RouterHi Next.js team and community,
I’m building an ecommerce app with Next.js App Router with these routes:
/users/[id]
for user profiles[...slug]
intended to handle multi-level dynamic paths such as:/electronics/mobiles/iphone
/electronics/mobiles
/electronics
The problems I’m encountering:
app/[...slug]/page.tsx
) causes conflicts with other dynamic routes like/users/[id]
, making those routes unreachable.app/[[...slug]]/page.tsx
) causes conflicts with the root/
route (app/page.tsx
) because the optional catch-all includes the root path.Is there a recommended pattern or best practice to:
/users/[id]
working properly,/
route independent, andShould routes be structured differently or is there a way to configure Next.js routing to avoid these collisions?
Other observations
I understand there are two common solutions:
Add a prefix for the catch-all route (e.g.
/category/[...slug]
) — but from an SEO perspective, this is not ideal for my use case since I want clean URLs directly under root.Avoid catch-all and manually create nested routes like
/[category]/[subcategory]/[product]
— but this feels less clean and will lead to a lot of duplicated code and complex routing logic.I would appreciate any guidance on best practices or alternative patterns.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions