我有一个简单的 nextjs 最新版本应用程序,一切都按预期工作。
除了 [id] 文件夹中的详细信息页面外,会引发 500 内部服务器错误,仅在手册页重新加载和仅在生产(我使用 netlify 和 firebase)。
在主页上:
async function getData() {
const res = await fetch('https://api.example.com/...')
return res.json()
}
export default async function Page() {
const posts = await getData()
return (
<ul>
{posts.map((post) => (
<li key={post.id}>
<Link href={`/blog/${post.id}`}>{post.title}</Link>
</li>
))}
</ul>
)
然后在 [id]/page.js 中:
一个仅包含显示 hello 功能的页面,(仅用于测试)
<p>Hello</p>
有人遇到过同样的情况,或者对此有见解吗?谢谢你。
一种解决方案:
看来这个问题只发生在部署到Netlify的nextjs中。
我将相同的应用程序重新部署到Vercel,但它没有显示出该行为的任何迹象,并且一切按预期工作。
更新 NextJS 版本解决了我的问题,从
14.0.2
到 14.2.5