开始出现奇怪的错误,导致构建失败,
我们的页面目录中有一个 post/[id].tsx 文件,该文件使用getStaticProps和getStaticPaths
- 道具
export const getStaticProps: GetStaticProps = async ({ params }) => {
const res: Response = await fetch(`${baseUrl}/api/products/${params.id}`);
const data: Product[] = await res.json();
return {
props: {
data,
},
};
};
Run Code Online (Sandbox Code Playgroud)
-- 路径
export const getStaticPaths: GetStaticPaths = async () => {
const res: Response = await fetch(`${baseUrl}/api/products`);
const { data } = await res.json();
const paths = data.map((product: Product) => ({
params: { id: product.id.toString() },
}));
return { paths, …Run Code Online (Sandbox Code Playgroud)