如何在NextJS中使用`not-found.tsx`中的元数据?

vd2z7a6w  于 2023-06-29  发布在  其他
关注(0)|答案(1)|浏览(114)

在我的NextJS应用程序中,我有一个not-found.tsx文件,在我的app目录的根目录中有一些简单的元数据:

import { Metadata } from "next";

export const metadata: Metadata = {
  title: "Page not found",
};

export default function NotFound() {
  return (
    <>
      <h1 className="mb-4 text-xl">Page not found</h1>
      <Link href="/">
        <button className="rounded bg-blue-600 px-3 py-1 text-sm text-gray-50 dark:bg-blue-700">
          Back to home
        </button>
      </Link>
    </>
  );
}

但是当我输入一个错误的URL时,我看到的URL本身就是页面的标题,而不是Page not found。我检查了head元素,其中没有title元素。
如何从找不到的页面导出元数据对象?
任何帮助将不胜感激!

相关问题