在网站上-使用renderToNodeStream()与SSR进行反应-在浏览客户端时,我使用React-Helmet在头部(ld + json脚本标签)中注入适当的微数据(不确定是否对SEO有用),以及在服务器上,我“欺骗”头盔不应该与renderToNodeStream配合使用的事实,如下所示:
(在渲染器上调用的自动绑定方法,不对服务器端执行任何操作)
head() {
return (
<Helmet>
<script type="application/ld+json">
{JSON.stringify(get***MicroData(this.props.***))}
</script>
</Helmet>
);
}
oResponse.write(
[
`<html>`,
`<head>`,
(...)
`<script type="application/ld+json" data-react-helmet="true">${getMicroData(***)}/script>`,
(...)
`</head>`,
].join(""),
);
(...)
const stream = ReactDOMServer[renderMethod]( // renderToNodeStream || renderToStaticNodeStream
<Provider store={store}>
<StaticRouter location={sURL} context={context}>
<RootContainer ***={***}/>
</StaticRouter>
</Provider>,
);
它似乎工作正常,只是想确保这段代码没有问题。.(水化)
谢谢!