【发布时间】:2021-08-30 00:54:07
【问题描述】:
- 如果我不打算运行“下一个导出”命令,是否需要使用 getStaticPaths?
- 能否使用 getStaticProps 在服务器端创建缓存结构并重新验证详细信息页面 (/user/1)?还是除了使用 SWR 或 getServerSideRender 之外别无选择?
- 在detail(/user/1)页面再次获取所有数据不是多余吗?
注意:用户详情页面可以每 60 秒刷新一次。即时更新并不重要。
export async function getStaticPaths() {
const res = await fetch('https://.../posts')
const posts = await res.json()
const paths = posts.map((post) => ({
params: { id: post.id },
}))
return { paths }
}
export async function getStaticProps({ params }) {
const res = await fetch(`https://.../posts/${params.id}`)
const post = await res.json()
return { props: { post } }
}
【问题讨论】:
标签: next.js server-side-rendering server-side