如何在 nextjs 应用程序路由器中添加新的自定义元属性?

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

我有nextjs 13.4版本的应用程序。我正在使用应用程序路由器系统。在页面的服务器组件中,我使用generateMetadata 来获取头元数据。在应用程序路由器中,我们无法使用“next/head”中的 Head。 generateMetadata 对我来说工作正常。我有代码:

export async function generateMetadata(): Promise<Metadata> {
  
  return {
    title: 'Modern Furniture Crafted with Elegance',
    description:
      'Experience the beauty and craftsmanship. Buy furniture for your home online.',
    viewport: 'width=device-width, initial-scale=1.0, user-scalable=yes',
    appleWebApp: { capable: true },
    openGraph: {
      title: 'Modern Furniture Crafted with Elegance',
      description:
        'Experience the beauty and craftsmanship. Buy furniture for your home online.',
    },
  };
}

现在我想添加一些新属性,我想要这个: 使用generateMetadata在头部

<meta property="product:brand" content="Facebook">
。如果我使用generateMetadata的其他属性,我得到
<meta name="product:brand" content="Facebook">
,在元标记中看到有名称字段,但我想要属性字段
"product:brand"

如何添加此元标记。

reactjs next.js next.js13
1个回答
0
投票

我有类似的要求,只需将

<meta>
标签放入头部即可为我工作。

export default function RootLayout({ children }) {
  return (
    <html lang="en" className="dark">
      <head>
        <meta property="fb:app_id" content="XXXXX" />
      </head>
....
© www.soinside.com 2019 - 2024. All rights reserved.