Next.js Discord

Discord Forum

SSG with dynamic path segment in Next12

Unanswered
Kerry Beagle posted this in #help-forum
Open in Discord
Kerry BeagleOP
I have a dynamic route defined that I would like to statically generate a template for, you can think of this as a shell (includes some request to headless CMS). The React components inside the shell would render on the client/do some requests to render the rest of the page. Is there a way to generate 1 template that is shared across all the dynamic paths? the issue is that i don't know how to do "getStaticPaths" since all the routes are truly dynamic/i dont want to generate templates for all of these routes as they would be the same.

11 Replies

If using getStaticProps on a dynamic route, it’s a prerequisite that you have to use getStaticPaths.

You can create a react component that is a “template” and import it on each page in a route. Do you know how to create components?
Kerry BeagleOP
Whats going on is this - I have a header and footer that has a dependency on Headless CMS data to render. I'd like to not make that call every time the page gets rendered based on a specific dynamic path segment
so what i was thinking was that could just happen at build time once, then the React code inside the page that doesn't know how to SSR will render normally/do CSR inside the Header/Footer shell
Kerry BeagleOP
yes!
🙏
@Kerry Beagle so what i was thinking was that could just happen at build time once, then the React code inside the page that doesn't know how to SSR will render normally/do CSR inside the Header/Footer shell
Sounds logical. You’ll need to fetch the data in getStaticProps on each page, then pass the data via props into the template.