我在 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>
Run Code Online (Sandbox Code Playgroud)
这是我的错误:
Objects are not valid as a React child (found: object with keys {@context, @type, address, colleague, email, image, jobTitle, name, …Run Code Online (Sandbox Code Playgroud) 我使用 nextjs 并且在使用 getInitialProps 时遇到问题。
我想在 getInitialProps 中使用我在 Post 组件中创建的变量。你可以看到我的男女生:
const Post = props => {
const router = useRouter()
let id = router.query.id
let urlTitle = router.query.title
return (
<Layout>
//somthing
</Layout>
)
}
Post.getInitialProps = async () => {
// i want to use {id} and {urlTitle} here
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做 ?!!!
我在我的新网站中使用 nextJS,但 SEO 和网站的速度对我来说非常重要。我想做的是防止加载额外的资源文件,而我不需要它们。例如,当我在主页时,我不需要在后台加载常见问题解答或关于页面的资源。我是否可以阻止网站上的这些额外负载?
先感谢您