Looking for opinion on how I should structure routes for this page
Unanswered
Nile Crocodile posted this in #help-forum
Nile CrocodileOP
Hello,
I would like to hear some opinions/suggestions on how should I structure routes for these tabs, since I would like to make it URL based, if you know what I mean. There are couple of ideas I was considering.
1. If product page was
2. That is one idea I had, the other one would be to persist current tab in search params (
3. Using [parallel](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes) route for each tab.
4. Say screw it and just fetch everything when user visits
These are just some ideas I had, if you can think of other solution or have a better one, or even some suggestion I'd love to hear it!
Thanks in advance :)
I would like to hear some opinions/suggestions on how should I structure routes for these tabs, since I would like to make it URL based, if you know what I mean. There are couple of ideas I was considering.
1. If product page was
/products/[slug]
, I was thinking default tab ("Product Details" for example) could be just rendered when someone visits /products/[slug]
, "Reviews" tab could lead to /products/[slug]/reviews
which will fetch and render reviews (and show loading skeleton while fetch is pending) and "FAQ" tab could lead to /products/[slug]/faq
which would fetch and render FAQs. So I don't have to get reviews and FAQs from DB if user is on other tab.2. That is one idea I had, the other one would be to persist current tab in search params (
?tab=details|reviews|faq
). But, if I'm not mistaken, this would prevent Next.js from caching those routes and therefore would fetch them every time I move to that tab. Whereas with first option I believe route would be cached, so when I visit it next time it would just show reviews without fetching or loading state.3. Using [parallel](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes) route for each tab.
4. Say screw it and just fetch everything when user visits
/products/[slug]
and then just conditionally render each tab.These are just some ideas I had, if you can think of other solution or have a better one, or even some suggestion I'd love to hear it!
Thanks in advance :)
3 Replies
I’m voting for 1 and 3, reserve search params for the state of the color, size, filters (latest, etc)
But somehow my head exploded and I can’t figure out this: in the 1st approach, how would you share the section on the top across pages? State isn’t the problem since it’ll be pull from the URL I assume.
Would you put it inside a layout along with the little tab nav?
But somehow my head exploded and I can’t figure out this: in the 1st approach, how would you share the section on the top across pages? State isn’t the problem since it’ll be pull from the URL I assume.
Would you put it inside a layout along with the little tab nav?
Asian black bear
@Dusky Flycatcher Please don't copy/paste AI-generated responses.
@luis_llanes I’m voting for 1 and 3, reserve search params for the state of the color, size, filters (latest, etc)
But somehow my head exploded and I can’t figure out this: in the 1st approach, how would you share the section on the top across pages? State isn’t the problem since it’ll be pull from the URL I assume.
Would you put it inside a layout along with the little tab nav?
Nile CrocodileOP
Yep, I was planning to put it in layout