Next.js Discord

Discord Forum

Nested dynamic routes

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
In order to create nested dynamic routes within app router, are we still forced to creating a route group first, and then each link being it's own page inside of that?

currently have a project structure where I require the following:

/case-study/{slug} and /case-study/{industry}/{slug}

15 Replies

American Crow
that would be something like
|_app
|____case-study
|_______[industry]
|_________page.tsx
|__________[slug]
|______________page.tsx

If you don't want to generateStaticParams in both page.tsx
You can either do it for both segements from the bottom up https://nextjs.org/docs/app/api-reference/functions/generate-static-params#generate-params-from-the-bottom-up
Or from the top down https://nextjs.org/docs/app/api-reference/functions/generate-static-params#generate-params-from-the-top-down
sorry for the intends it's a bit fucked i did it by hand like a maniac
American Crow
i mean you can also catch all like you did it with the ...
Hmm you got me thinking why I would got with my approach.
Don't want to say anything wrong i gonna research this
@American Crow i mean you can also catch all like you did it with the ... Hmm you got me thinking why I would got with my approach. Don't want to say anything wrong i gonna research this
Brown bearOP
yeah, that's where i'm at, I recall a colleague at one point saying the current solution for app router is route groups, but not sure if there's been a better way by now
American Crow
in your example
/case-study/{slug} and /case-study/{industry}/{slug}

How do you know that left side {slug} is not a {industry} ?
Let's say case-study/banking
Banking being an industry logically speaking.
Assuming beacuse its just 1 segment?
So case-study/banking/bank-of-england should trigger the right side?
Does that mean that case-study/bank-of-england must exist too though? Are these two {slugs} connected? Is what i am trying to ask
@American Crow Does that mean that `case-study/bank-of-england` must exist too though? Are these two {slugs} connected? Is what i am trying to ask
Brown bearOP
they're not connected directly no, in your example case-study/bank-of-england is just the project/company, and then you'd look up all relevant studies based on banking or finance for example
so the idea would be /case-study/c/{banking} however, doesn't seem like you can do multiple dynamic routes without route groups
American Crow
Hm yea i tried to come up with something but I can't. Pretty sure you are right. I would not even have thought of route groups for this as a solution.
I came here with the intention to help but today sir you helped my understanding
@American Crow Hm yea i tried to come up with something but I can't. Pretty sure you are right. I would not even have thought of route groups for this as a solution. I came here with the intention to help but today sir you helped my understanding
Brown bearOP
glad I was able to help as well 🙂 I don't particularly like the routing system app router provides, but I do like a few of the things it solves
American Crow
Lets see if one of the veterans joins this thread and might have something we both didnt think of
@American Crow Lets see if one of the veterans joins this thread and might have something we both didnt think of
Brown bearOP
I ended up finding a solution that works 🙂
@Brown bear I ended up finding a solution that works 🙂
American Crow
interesting what does the t\ do
@American Crow interesting what does the t\ do
Brown bearOP
in that context it allows you to have /projects/t/{slug} so just routes the topic/category pathname and then category is dynamic to query the specific category