通过组件渲染时,一些元标记未添加到头
我有一个具有以下结构的metatags.tsx
组件;
const DEFAULT_IMAGE = {
url: OgImage, //cloudinary url
width: '1200',
height: '630',
};
const MetaTags: FunctionComponent<Props> = (props) => {
const url = props.url ? `${BASE_URL}${props.url}` : BASE_URL;
const title = props.title || DEFAULT_TITLE;
const description = props.description || DEFAULT_DESCRIPTION;
const image = props.image || DEFAULT_IMAGE;
const type = props.type || DEFAULT_TYPE;
return (
<>
<meta name="description" content={description} />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:card" content="summary" />
<meta property="og:title" content={title} />
<meta property="og:url" content={url} />
<meta property="og:description" content={description} />
<meta property="og:type" content={type} />
<meta property="og:site_name" content="Example.com" />
<meta property="og:locale" content="en_GB" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:user_generated" content="false" />
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width} />
<meta property="og:image:height" content={image.height} />
</>
);
};
export default MetaTags;
然后,我将此metatags
在页面组件上的组件类似,因此
import React, { FC } from 'react';
import Head from 'next/head';
import MetaTags from '../head/MetaTags';
const ExamplePage: FC = () => {
return (
<>
<Head>
<title>Example Page</title>
<MetaTags
title="Example Page"
url="example-page"
description="Example Page Description"
/>
</Head>
</>
);
};
,以下meta标签不会添加到head> head
tag
<meta property="og:image:user_generated" content="false" />
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width} />
<meta property="og:image:height" content={image.height} />
如果我直接在head
组件中的页面组件上添加元标记,而不是使用metatags
组件返回元标记。
使用版本
I have a MetaTags.tsx
component that has the following structure;
const DEFAULT_IMAGE = {
url: OgImage, //cloudinary url
width: '1200',
height: '630',
};
const MetaTags: FunctionComponent<Props> = (props) => {
const url = props.url ? `${BASE_URL}${props.url}` : BASE_URL;
const title = props.title || DEFAULT_TITLE;
const description = props.description || DEFAULT_DESCRIPTION;
const image = props.image || DEFAULT_IMAGE;
const type = props.type || DEFAULT_TYPE;
return (
<>
<meta name="description" content={description} />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:card" content="summary" />
<meta property="og:title" content={title} />
<meta property="og:url" content={url} />
<meta property="og:description" content={description} />
<meta property="og:type" content={type} />
<meta property="og:site_name" content="Example.com" />
<meta property="og:locale" content="en_GB" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:user_generated" content="false" />
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width} />
<meta property="og:image:height" content={image.height} />
</>
);
};
export default MetaTags;
Then I import this MetaTags
component on a page component like so
import React, { FC } from 'react';
import Head from 'next/head';
import MetaTags from '../head/MetaTags';
const ExamplePage: FC = () => {
return (
<>
<Head>
<title>Example Page</title>
<MetaTags
title="Example Page"
url="example-page"
description="Example Page Description"
/>
</Head>
</>
);
};
However, the following meta tags do not get added to the head
tag
<meta property="og:image:user_generated" content="false" />
<meta property="og:image" content={image.url} />
<meta property="og:image:width" content={image.width} />
<meta property="og:image:height" content={image.height} />
Same issue occurs if I add the meta tags directly on the page component inside the Head
component, instead of using the MetaTags
component to return the meta tags.
Using version [email protected]
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论