If you are creating a dynamic page eg: product/[slug].tsx
then even if you don’t want to create any page on build time you need to create a getStaticPaths
method to set the fallback
property and let NextJS know what to do when the page you are trying to get doesn’t exist.
export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
return {
paths: [], //indicates that no page needs be created at build time
fallback: 'blocking' //indicates the type of fallback
}
}
getStaticPaths
does mainly two things:
Indicate which paths should be created on build time (returning a
paths
array)Indicate what to do when a certain page eg: “product/myProduct123” doesn’t exist in the NextJS Cache (returning a
fallback
type)