小编nie*_*oof的帖子

由于参数未定义,下一个 js 在使用 getStaticProps 构建时失败

开始出现奇怪的错误,导致构建失败,

我们的页面目录中有一个 post/[id].tsx 文件,该文件使用getStaticPropsgetStaticPaths

- 道具

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)

typescript next.js

5
推荐指数
2
解决办法
3799
查看次数

标签 统计

next.js ×1

typescript ×1