Error: getStaticPaths is required for dynamic SSG pages and is missing for '/blogs/[post]'

1k views Asked by At

I try to npm run build .

Build error occurred Error: getStaticPaths is required for dynamic SSG pages and is missing for '/blogs/[post]'.

my code:

function post (props){
   console.log(props);
   return(
       <div>
           test
       </div>
   )
}
export const getStaticProps = async(post)=>{
   const blogPost =  await axios({
       method: 'get',
       url: `api url=${post}`});

   return{
       props:{params:blogPost}
   }
}

export default withRouter(post);

1

There are 1 answers

0
SlothOverlord On

Check the documentation on getStaticPaths. You can find a good example there.

Your /blogs/[post] needs all the possible paths of your posts to know how many of them should next build. So in [post] you need to implement getStaticPaths that will fetch all slugs of your posts