getStaticPaths - data.map 不是函数

Owa*_*ufi 3 javascript strapi axios next.js

我在我的博客项目中使用 Strapi 和 Next.js

我正在尝试通过在pages/posts/[id].js中使用[id].js来制作动态页面

但是,问题是当我尝试通过 getStaticPaths() 内的 Strapi API 进行映射时,它给我一个错误:data.map is not Defined

注意:- 我正在使用 NextJS V12.0.8 和 Strapi V4.0.4

下面是我的代码

export async function getStaticPaths() {
  const postsRes = await axios.get("http://localhost:1337/api/posts?populate=image");
 
  const paths = postsRes.map((post) => {
    return { params: {id: post.id.toString()} }
  });

  // const paths = { params: {id: '1' } }
    
  return {
    paths,
    fallback: false
 
  }
 
}
Run Code Online (Sandbox Code Playgroud)

完整[id].js页面代码链接 - https://pastebin.com/SnzLirys

错误屏幕截图 - https://prnt.sc/26ha6z5

小智 8

您所需要做的就是按 ctrl + c 重新启动 npm run dev,然后重新运行 dev