I am currently working on a blog project using Strapi in conjunction with Next.js
My goal is to create dynamic pages by utilizing [id].js within the pages/posts/[id].js structure
However, I've encountered an issue while attempting to map through the Strapi API inside getStaticPaths(). The error message states that data.map is not defined
Important note: I am running Next.js version 12.0.8 and Strapi version 4.0.4
Below you can find the snippet of code causing the problem:
export async function getStaticPaths() {
const postsRes = await axios.get("http://localhost:1337/api/posts?populate=image");
const paths = postsRes.map((post) => {
return { params: {id: post.id.toString()} }
});
// const paths = { params: {id: '1' } }
return {
paths,
fallback: false
}
}
To view the complete code for the [id].js
page, click on this link - https://pastebin.com/SnzLirys
If you'd like to see a screenshot of the error, you can check it out here -