Next.js App Router中如何添加自定义meta property属性?
解决Next.js 13.4 App Router中生成带property属性的元标签问题
在Next.js 13.4的App Router架构下,要生成带有property属性的自定义元标签(如<meta property="product:brand" content="Facebook">),需借助generateMetadata返回对象中的meta数组来定义这类标签,常规字段配置无法生成property属性的标签。
修改后的代码示例如下:
import type { Metadata } from 'next'; 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.', }, // 添加带property属性的自定义元标签 meta: [ { property: 'product:brand', content: 'Facebook', }, ], }; }
meta数组支持添加多条自定义元标签,每条通过property指定属性名、content设置对应内容,Next.js会自动生成符合要求的<meta>标签。
内容的提问来源于stack exchange,提问作者jhon arab
相关产品推荐
相关产品推荐

