Next.js Discord

Discord Forum

How to display two different pages depending on dynamic URL.

Unanswered
Smith's Longspur posted this in #help-forum
Open in Discord
Smith's LongspurOP
Hello, I want to display two different pages depending on the URL.

Routes:
http://localhost:3000/school/harvard
http://localhost:3000/school/harvard/profile

the parameters: "harvard" and "profile" are dynamic

To manage the first one, I use the following folder structure: /school/[slug] and it works fine.

But I can't manage the second.

I changed the folder structure from the previous version to this one: /school/[...slug] but this captures all the routes and only displays the same page; that of: http://localhost:3000/school/harvard

Thank you for your help.

23 Replies

Smith's LongspurOP
is "uni" special word like "slug" ? and do i need to change de folder structure?
In your question you mentioned /school/[slug] – “slug” here is not a special word
You can use any words
Smith's LongspurOP
ah okay
this is my folder stucture
Is the “profile” part in your url dynamic? Because I feel it shouldn’t be…
Smith's LongspurOP
i get it
is okay now
Use

app/school/[school]/[subPage]/page.tsx
(school=harvard, subpage=profile)
Or app/school/[school]/profile/page.tsx
Depending on your need
Smith's LongspurOP
i just do like you said
thanks for your help
:1000:
@Smith's Longspur Click to see attachment
Yes this works though slug will be harvard and uni will be profile which I doubt is what you want
At least rename the folders to reflect the meaning of the variables
But yeah that’s the gist of it
Smith's LongspurOP
"harvard" and "profile" are dynamic; for example they can be "cambridge" and "settings"
@Smith's Longspur "harvard" and "profile" are dynamic; for example they can be "cambridge" and "settings"
You likely need this instead

app/school/
  [uni]/
    page.tsx # /school/harvard
    settings/
      page.tsx # /school/harvard/settings
    profile/
      page.tsx # /school/harvard/profile


Dynamic route segments should be used for dynamic data that you fetch rather than something like “settings” or “profile” or “dashboard”
Smith's LongspurOP
Oh Interessing; I understand now what you mean :1000:
thank you for your clarification