0

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);

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Raana Tashakori
  • 407
  • 1
  • 6
  • 18
  • 1
    Dynamic routes (in your case `/blogs/[post]`) that use `getStaticProps` require `getStaticPaths` to be defined. I'd recommend you have a read through [`getStaticPaths` docs](https://nextjs.org/docs/basic-features/data-fetching#getstaticpaths-static-generation). – juliomalves Apr 30 '21 at 13:12
  • Does this answer your question? [Error: getStaticPaths is required for dynamic SSG pages and is missing for "xxx". NextJS](https://stackoverflow.com/questions/65783199/error-getstaticpaths-is-required-for-dynamic-ssg-pages-and-is-missing-for-xxx) – juliomalves Apr 30 '21 at 13:13

1 Answers1

1

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

SlothOverlord
  • 1,655
  • 1
  • 6
  • 16