@Jack H Nemitz Thanks for asking question-
For Dynamic routes, The pages/project/[slug].js file implements code that tells Next.js what pages to generate based on associated data. In Next.js, each page powered by dynamic routes needs to implement getStaticPaths
and getStaticProps
to give Next.js the information it needs to build pages that match possible route values.
Inside getStaticPaths
, each data object is used to create a list of paths all possible pages.
export async function getStaticPaths() {
const paths = projects.map((project) => ({
params: { path: project.slug },
}))
return { paths, fallback: false };
}
The getStaticProps
function is run each time a page is generated. Based off the parameter values, the function matches the full data object to the page being generated. Once the data object is returned, it is used as the context for the generated page.
export async function getStaticProps({ params }) {
const project = projects.find(proj => proj.slug === params.path);
return { props: { project } };
}
Reference: https://github.com/staticwebdev/nextjs-starter
Let us know if further query or issue remains.