gpt4 book ai didi

javascript - NextJS 自定义 404 页面未显示

转载 作者:行者123 更新时间:2023-12-02 01:54:49 25 4
gpt4 key购买 nike

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

export default function NotFound() {
return <h1>404 - Page Not Found</h1>
}

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

import Error from 'next/error'

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

return <h1>{organization.name}</h1>
}

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

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

最佳答案

你是reusing the built-in error page .

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

关于javascript - NextJS 自定义 404 页面未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69755728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com