如何解决在 CSR 中移动路线时是否应该更改 <meta robots> 标签?
我在 React 中使用了头盔和 react-router-dom。 目前,第一个屏幕进入SSR,然后作为CSR运行。
对于会员注册和我的页面,meta robots标签实现为'noindex',否则实现为'index'。
目前,将元数据导入到 SSR 后,robots 元标记不会发生变化。
react 是 SPA,每当页面通过路由移动时,更改 robots 元标记以及标题、描述等是否正确?
在ssr中像这样指定Meta标签
let robotsIndex = 'noindex';
allowPageList.forEach(allow => {
if (statusCode === 200 && (path.includes(allow) || path === '/'))
robotsIndex = 'index';
});
ssrParams.robotsIndex = robotsIndex;
在 csr 中使用头盔更改 Meta 标签
return (
<Helmet>
{/* title */}
<title>{headTitle}</title>
<link rel="canonical" href={canonical} />
{/* meta */}
<meta name='title' content={headTitle} />
<meta name='description' content={metaDescription} />
<meta name='keywords' content={metaKeywords.join(',')} />
{/* og:meta */}
<meta property='og:title' content={headTitle} />
<meta property='og:image' content={metaImage} />
<meta property="og:image:width" content="500" />
<meta property="og:image:height" content="500" />
<meta property='og:description' content={metaDescription} />
<meta property="og:url" content={metaUrl} />
{/* twitter */}
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content={headTitle} />
<meta name="twitter:image:src" content={metaImage} />
<meta name="twitter:description" content={metaDescription} />
{/* etc */}
<link rel="image_src" href={metaImage} />
</Helmet>
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。