getstaticpaths no próximojs
//pages\news\[slug].tsx
export async function getStaticPaths() {
const res = await fetch(`${baseUrl}/wp-json/wp/v2/posts`)
const posts = await res.json()
const paths = posts.map(({ slug }) => ({ params: { slug: `${slug}` } }))
return {
paths,
fallback: true,
//The paths that have not been generated at build time will not result in a 404 page.
//Instead, fallback: true This will be used to automatically render
//the page with the required props.
}
}
export async function getStaticProps(context) {
const resPost = await fetch(`${baseUrl}/wp-json/wp/v2/posts?slug=${context.params.slug}`)
const post = await resPost.json()
return {
props: {
post,
},
revalidate: 10,
}
}
Shirshak kandel