Error: A required parameter (slug) was not provided as a string in getStaticPaths for /posts/[slug]

You have mismatch between filename dynamic key and what you expect in the code.

You return blogSlug key in getStaticPaths:

const paths = posts.map(post => ({ params: { blogSlug: post.slug } }));

but your file is named [slug].js and you expect a slug key here in getStaticProps:

const blogSlug = context.params.slug;

It should be consistent, in this case it should be named slug everywhere.

Leave a Comment