I create a specific Blog preview page according to specific id on NEXT JS using getStaticProps and getStaticPath but when I click on Button its shows an error :
A required parameter (id) was not provided as a string in getStaticPaths for /Blogs/[id]
This is my code below:
export const getStaticPaths = async () => {
const res = await axios.post(`API/blog/`);
const articles = await res.data.success
const paths = articles.map( blog => {
return {
params: { id: blog._id.toString()},
}
})
return {
paths,
fallback: false
}
}
export const getStaticProps = async (context) => {
const id = context.params._id;
const res = await axios.post(`API` + id);
const articles = await res.data.success;
return {
props: {blog: articles}
}
}
I hope some find the but in this code.