NextJS not-found.tsx 返回 HTTP 200 状态码

问题描述 投票:0回答:1

当我使用 NextJS 的 not-found.tsx 文件时,它呈现良好但它返回 200 状态代码而不是 404。知道为什么吗?我该如何解决这个问题?

next.js http-status-code-404
1个回答
0
投票

我想既然你要返回一个有效的自定义组件,它将它设置为 200.

如果删除

not-found.tsx
并使用这个

import { notFound } from 'next/navigation'

组件内部

if(true) notFound()

如果你将鼠标悬停在

notFound

在 React 服务器组件中使用时,这将设置状态代码 到 404。当在自定义应用程序路由中使用时,它只会发送 404 状态。

© www.soinside.com 2019 - 2024. All rights reserved.