I want to use getStaticPaths for my posts blog with dynamic routes but I get an error while building.
My folder with dynamic routes :
pages/articles/[category]/[slug].js
My Link Navigation:
<Link href={`/article/${category}/${slug}`} passHref>
<Card>
...some data
</Card>
<Link />
My getStaticPaths:
export async function getStaticPaths () {
// retrieve data from cms
const data = await getAllPreviewPosts()
// generate the paths
const paths = data.map( ({ fields: { slug , stackName } }) => ({
params: { category: stackName, slug: slug }
}))
return {
paths,
fallback: false
}
}
export async function getStaticProps () {
/* ... get data from cms */
}
But when I run npm run build I get this error:
Error: getStaticPaths can only be used with dynamic pages, not '/'.
getStaticPaths?