routes
Answered
Gouty oak gall posted this in #help-forum
Gouty oak gallOP
help?
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
?
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
42 Replies
Asian black bear
No because how should Next deduce which page to serve for a route like
/home/foo
.Gouty oak gallOP
i dont understand why this only happens with dynamic routes while static routes dont have this problem
to exapand on what near said, think about it like this:
if I go to
pls mark as solution if this helped!
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!
Gouty oak gallOP
i understand but like why this only happens with dynamic routes while static routes dont have this problem
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
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?
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
soo i was curious, guess we learn smt new everyday
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
so
Gouty oak gallOP
how to mark solved
ok lemme properly answer this for you
Gouty oak gallOP
yes please
when you do home/[account]/page.tsx
that captures any route that you put after home
so home/ajsfh and home/foo and home/anything will all redirect to the same page.tsx
Answer
Gouty oak gallOP
okayyyyyyyyy
that's why you can't have multiple
Gouty oak gallOP
so on one level, we can have only one [] or [...] right
and that doesnt apply to static routes
not sure what [...] is, but sure
Gouty oak gallOP
catch all 😭
my bad
catch all routes
ooh right ok I didn't see the syntax bc I'm used to seeing a name
Gouty oak gallOP
yeah that was a bad usage from my end
should have been [...smt]
Gouty oak gallOP
okay thank you
fyi, dynamic routes opt the page into dynamic rendering, but a page can be opted into dynamic rendering and not be a dynamic route
Gouty oak gallOP
howww thatt
ig I'm probably just making this more complicated
but just try to read the docs more in general