gpt4 book ai didi

reactjs - 我如何在 nextjs 中使用 application/ld+json

转载 作者:行者123 更新时间:2023-12-03 17:55:29 24 4
gpt4 key购买 nike

我在 next js 中有一个 Layout 并且我使用 Head 组件。
我想使用模式 json 但我有一个错误。

这是我的代码:

<Head>
<script type="application/ld+json">
{{
"@context": "http://schema.org",
"@type": "Person",
address: {
"@type": "PostalAddress",
addressLocality: "Seattle",
addressRegion: "WA",
postalCode: "98052",
streetAddress: "20341 Whitworth Institute 405 N. Whitworth"
},
colleague: [
"http://www.xyz.edu/students/alicejones.html",
"http://www.xyz.edu/students/bobsmith.html"
],
email: "mailto:jane-doe@xyz.edu",
image: "janedoe.jpg",
jobTitle: "Professor",
name: "Jane Doe",
telephone: "(425) 123-4567",
url: "http://www.janedoe.com"
}}
</script>
</Head>

这是我的错误:
Objects are not valid as a React child (found: object with keys {@context, @type, address, colleague, email, image, jobTitle, name, telephone, url}). 

If you meant to render a collection of children, use an array instead. in script (at Layout.js:130) in head in Head (at _document.js:43) in html in Html (at _document.js:42) in MyDocument in Context.Provider in Context.Provider

请帮忙!

最佳答案

您需要使用 dangerouslySetInnerHTML为了放置您的架构数据。

<Head>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
/>
</Head>

关于reactjs - 我如何在 nextjs 中使用 application/ld+json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59318263/

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