export const getStaticPaths = async () => {
return {
paths: [
{ params: { slug: 'article-1' } },
{ params: { slug: 'article-2' } },
],
fallback: false,
}
}
export const getStaticProps = async ({ params }) => {
// params is undefined
return {
props: { slug: '' },
}
}
getStaticProps
得到这个对象,
{ locales: undefined, locale: undefined, defaultLocale: undefined }
并且缺少 params 键。 getStaticPaths
必须传递参数,但由于某种原因 getStaticProps
没有它。
答案 0 :(得分:0)
发现错误,这两个函数应该是在动态路由中调用的。 [slug].js
就我而言。我在文件 pages/blog/index.js
中调用了它们,其中没有传递参数,因为它不是动态路由。
将函数移至页面 pages/blog/[slug].js
使其工作。