问题描述
我在 React 中使用了头盔和 react-router-dom。 目前,第一个屏幕进入SSR,然后作为CSR运行。
对于会员注册和我的页面,Meta robots标签实现为'noindex',否则实现为'index'。
目前,将元数据导入到 SSR 后,robots 元标记不会发生变化。
react 是 SPA,每当页面通过路由移动时,更改 robots 元标记以及标题、描述等是否正确?
let robotsIndex = 'noindex';
allowPagelist.forEach(allow => {
if (statusCode === 200 && (path.includes(allow) || path === '/'))
robotsIndex = 'index';
});
ssrParams.robotsIndex = robotsIndex;
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 (将#修改为@)