Next.js Discord

Discord Forum

routes

Answered
Gouty oak gall posted this in #help-forum
Open in Discord
Avatar
Gouty oak gallOP
help?
Error: You cannot use different slug names for the same dynamic path ('account' !== 'profile').


can i not have two dynamic routes on same level? cus when i go to profile page, it displays the contents of account page lol

src/app/home

home/[account]/page.js
home/[profile]/page.js

?
Answered by Lukas
so home/ajsfh and home/foo and home/anything will all redirect to the same page.tsx
View full answer

42 Replies

Avatar
Asian black bear
No because how should Next deduce which page to serve for a route like /home/foo.
Avatar
Gouty oak gallOP
i dont understand why this only happens with dynamic routes while static routes dont have this problem
Avatar
to exapand on what near said, think about it like this:
if I go to home/foo, nextjs doesn't know where to take you. Next has no way of knowing if that's an account or a profile. it would be like having two page.js files for the home route. Instead, you could do home/account/[id]/page.js and home/profile/[id]/page.js

pls mark as solution if this helped!
Avatar
Gouty oak gallOP
i understand but like why this only happens with dynamic routes while static routes dont have this problem
Avatar
Asian black bear
Because static routes only map to a single unique path.
If I navigate to /home/foo it will attempt to render /home/foo/page.tsx
The route you navigate to maps strictly to a single path in the file system, there are no ambiguous paths there.
Unlike with your example where two distinct pages would be candidates for the same path
Avatar
I couldn't have said it better
@Gouty oak gall can you share a bit more about your use case? are you trying to display multiple pages on one route?
Avatar
Gouty oak gallOP
okay i understand it now kinda lol
just getting started w nextjs and i made those two folders in a same folder, when i went to home/profile, it displayed the contents of account page and when i restarted the server, it THEN only gave me this error

Error: You cannot use different slug names for the same dynamic path ('account' !== 'profile').


soo i was curious, guess we learn smt new everyday
thank you Lucas and Near
Avatar
o
so
Avatar
Gouty oak gallOP
how to mark solved
Avatar
ok lemme properly answer this for you
Avatar
Gouty oak gallOP
yes please
Avatar
when you do home/[account]/page.tsx
that captures any route that you put after home
Avatar
so home/ajsfh and home/foo and home/anything will all redirect to the same page.tsx
Answer
Avatar
Gouty oak gallOP
okayyyyyyyyy
Avatar
that's why you can't have multiple
Avatar
Gouty oak gallOP
so on one level, we can have only one [] or [...] right
and that doesnt apply to static routes
Avatar
not sure what [...] is, but sure
Avatar
Gouty oak gallOP
catch all 😭
my bad
catch all routes
Avatar
ooh right ok I didn't see the syntax bc I'm used to seeing a name
Avatar
Gouty oak gallOP
yeah that was a bad usage from my end
should have been [...smt]
Avatar
right
anyways
to mark as solution
you just do this
Image
Avatar
Gouty oak gallOP
okay thank you
Avatar
fyi, dynamic routes opt the page into dynamic rendering, but a page can be opted into dynamic rendering and not be a dynamic route
Avatar
Gouty oak gallOP
howww thatt
Avatar
ig I'm probably just making this more complicated
but just try to read the docs more in general