我已阅读 Next.js 文档,并且知道如何使用 getStaticProps 和 getStaticPaths。
我想念的是他们实际上是如何一起工作的?我的意思是 getStaticProps 何时被调用(当与 [slug].js 文件中的 getStaticPaths 一起使用时)?
在我的分析中(我不确定),我认为 getStaticProps 是在 getStaticPaths 循环内“以某种方式”调用的,因此 getStaticPaths 为其“paths”变量中的每个对象运行 getStaticProps,对吗?
在这段代码片段中查找我的评论:
export async function getStaticPaths() {
// Call an external API endpoint to get posts
const res = await fetch('https://.../posts')
const posts = await res.json()
// Get the paths we want to pre-render based on posts
const paths = posts.map((post) => ({
params: { id: post.id },
}))
// getStaticProps is called somewhere in the previous loop???
return { …
Run Code Online (Sandbox Code Playgroud)