【发布时间】:2021-07-22 12:39:16
【问题描述】:
我想为我的帖子博客使用 getStaticPaths 并使用动态路由,但在构建时出现错误。
我的动态路由文件夹:
页面/文章/[类别]/[slug].js
我的链接导航:
<Link href={`/article/${category}/${slug}`} passHref>
<Card>
...some data
</Card>
<Link />
我的 getStaticPaths:
export async function getStaticPaths () {
// retrieve data from cms
const data = await getAllPreviewPosts()
// generate the paths
const paths = data.map( ({ fields: { slug , stackName } }) => ({
params: { category: stackName, slug: slug }
}))
return {
paths,
fallback: false
}
}
export async function getStaticProps () {
/* ... get data from cms */
}
但是当我运行npm run build 时,我得到了这个错误:
Error: getStaticPaths can only be used with dynamic pages, not '/'.
【问题讨论】:
-
getStaticPaths在哪个文件中?
标签: next.js dynamic-routing getstaticpaths