I'm trying to fetch data from an API that varies depending on the URL, trying to do it with withRouter but it seems it won't work inside getStaticProps.
I currently have the following code:
export async function getStaticProps({ router }) {
const pageRequest = `http://localhost:3000/api/posts/${router.query.pid}`
const res = await fetch(pageRequest)
const json = await res.json()
return {
props: {
json,
},
}
}
It's returning:
TypeError: Cannot read property 'query' of undefined
What's the proper way to get the variable in the URL to use inside getStaticProps?