Next.js Discord

Discord Forum

Confused on Dynamic Routing with [slug] & [...slug]

Answered
Thrianta posted this in #help-forum
Open in Discord
ThriantaOP
Project Environment: Next 14 w/ /app Router, Typescript, Sanity Studio backend / headless cms w/ next/sanity
Project is a photo gallery app ( or this portion at least ) I will speak of my data structure in sanity terms feel free to ask for clarification
I have a schema for a document object gallery that has some basic stuff like photographer, date gallery title, then it takes an array of photos ( rendering this is where i am having the trouble )

So here is the current structure of the parts involved
/src/app/(user)/ will serve as the root for this point this is where all my client side app lives
inside we have the following structure
| - /gallery
| - - page.tsx Entry point to the gallery renders the galleryCategories as choices routes to /gallerycategory/[slug]/page.tsx
| - - - /...[slug]
| - - - page.tsx Where the problem happens, should render collection of photos from the array in the schema mentioned above
| - /gallerycategory
| - - - /[slug]
| - - - page.tsx Sub categories for each main category are rendered and rout to /gallery/[...slug]/page.tsx

We get slugs from the galleryCategory schema that looks like: landscape, photojournalism, portrait, ect
These are rendered out on /gallery and then navigate to /gallerycategories/[slug] to display the sub choices.

From the gallery schema we get slugs that look like: (from landscape for example) mountains, waterways, forestry, aerials, and inside this object is where the photo arrays are located
These are rendered on /gallerycategory/[slug] and will navigate to /gallery/[slug]

I ended up routing in this odd way trying to avoid the need for nested slugs originally tried that and found thats not allowed.
I spent some time trying to debug the type definitions and query and how I was rendering the data with out every considering if i was setting the routing structure up correctly before it finally hit me this could also be a factor.

honestly at this point I am big time confused and could just use some help
Answered by Thrianta
Seems the routing strange as it is does work correctly back to troubleshooting my query types and fetches seems the more I do the worse it gets ><
View full answer

2 Replies

ThriantaOP
Seems the routing strange as it is does work correctly back to troubleshooting my query types and fetches seems the more I do the worse it gets ><
Answer
ThriantaOP
The catchall slug route was bad for the set up, i had it in there for testing and forgot to take it out, it got me stuck bad