使用页面文件夹设置 NextJS 站点的标题

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

我正在尝试设置我的 NextJS 网站的标题。在文档中,我看到推荐的方法是导出具有所需标题的元数据常量:

import { Metadata } from 'next';

export const metadata: Metadata = {
  title: 'New Title',
};

但是,界面需要位于

app
文件夹中的文件中。问题是我的项目没有
app
文件夹,而是
src/pages

我尝试从

metadata
src/pages/index.page.tsx
src/pages/_app.page.tsx
导出
src/pages/_document.page.tsx
const,但没有成功。

有什么想法我该怎么做吗?

next.js metadata
1个回答
0
投票

元数据仅支持应用程序路由器,不支持页面路由器,您需要使用

next/head
组件在页面路由器中渲染元数据。

参考资料 - https://nextjs.org/docs/app/building-your-application/optimizing/metadata

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