Nextjs| getStaticPaths|错误:超过呼叫重试次数

gcmastyq  于 2023-10-18  发布在  其他
关注(0)|答案(1)|浏览(95)

当我进入动态slug页面时,出现了“Call retries were exceeded”错误,根据github的讨论,我将我的项目从13版本降级到12版本,但仍然出现同样的问题。让我分享我的错误截图第一,然后我会分享我的代码了。

slug.js

export const getStaticPaths = async () => {

  const res = await axios(process.env.NEXT_PUBLIC_API_URL+'/products');
  const products_arr = await res.data;
  const paths = products_arr.map( (pr) => ({
   params: { slug: pr.slug }
  }))

  return {
    paths,
    fallback: "blocking",
  };
}

export const getStaticProps = async ({params}) => {

  try {
    const res = await axios(`${process.env.NEXT_PUBLIC_API_URL}/products/${params.slug}`);
    const product = await res.data;
    return {
      props: { product }
    }
  } catch (error) {
      console.error(error);
      return { notFound: true };
  }

}

package.json

{
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@tailwindcss/typography": "^0.5.9",
    "axios": "^1.3.4",
    "flowbite": "^1.6.3",
    "flowbite-react": "^0.4.1",
    "next": "12.2.2",
    "next-themes": "^0.2.1",
    "patch-package": "^7.0.0",
    "pure-react-carousel": "^1.30.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-icons": "^4.7.1",
    "swiper": "^8.4.5",
    "swr": "^2.1.0"
  },
  "devDependencies": {
    "@types/node": "20.2.5",
    "@types/react": "18.2.7",
    "autoprefixer": "^10.4.12",
    "postcss": "^8.4.18",
    "tailwindcss": "^3.2.4",
    "typescript": "4.9.4"
  }
}
isr3a4wc

isr3a4wc1#

我在NextJs 13.4.5中遇到了同样的错误,下面的方法对我很有效。在我的例子中,我把我的文件/目录嵌套在app文件夹中,如下所示:“sales/[. slug]/page.tsx”。
在[. slug]下的.tsx页面中,我得到的查询参数为:

export default function DetailsPage({ params }: { params: { slug: 'title' } }) {
    const title = params.slug;    
    return (
        <div>Current viewing {title}</div>
    )
}

相关问题