NextJS 自定义 404 页面未显示

Skh*_*haz 3 javascript typescript next.js

我有一个pages/404.ts包含以下内容的自定义:

export default function NotFound() {
  return <h1>404 - Page Not Found</h1>
}
Run Code Online (Sandbox Code Playgroud)

我还有另一个页面,当某个组织为空时显示 404:

import Error from 'next/error'

const Slug: NextPage<SlugProps> = ({ organization }) => {
  if (!organization) {
    return <Error statusCode={404} />
  }

  return <h1>{organization.name}</h1>
}
Run Code Online (Sandbox Code Playgroud)

我想要 NextJS 显示我的自定义 404 页面,而不是显示默认页面

我需要做什么才能显示我的404 页面?

Ben*_*Ben 5

您正在重用内置错误页面

如果您想在动态路由中显示自定义 404,只需导入您的NotFound组件并返回即可。