我正在使用ReactJS为一个简单的可过滤项目列表提供支持,它可以很好地满足我的需求。
I'm using ReactJS to power a simple filterable item list and it works quite well for my need.
问题是我需要渲染标记服务器出于搜索引擎优化的原因,但当我调用 React.renderComponent()时,它将现有的标记替换为React生成的标记。
The problem is that I need to render the markup on the server for SEO reasons, but when I call React.renderComponent() it replace the existing markup with the one generated by React.
在React的文档中搜索我发现了这个注释:
Searching in React's docs I found this note:
React.renderComponent()替换你传递的容器节点的内容将来,有可能在不覆盖现有子节点的情况下将组件插入现有DOM节点。
React.renderComponent() replaces the contents of the container node you pass in. In the future, it may be possible to insert a component to an existing DOM node without overwriting the existing children.
此外我不能使用 React.renderComponentToString()生成标记服务器端,因为我的后端在PHP上运行...
Moreover I can't use React.renderComponentToString() to generate the markup server-side because my backend runs on PHP...
是否有任何(即使是hackish)方式来实现当前版本(0.11.2)?
Is there any (even if hackish) way to achieve this with the current release (0.11.2)?
我认为如果可以通过标记生成renderComponentToString ()应该有一种模拟结果的方法吗?
I suppose that if that's possible with markup generated by renderComponentToString() there should be a way to mock that result?
感谢您的任何建议!
推荐答案您可以查看 github/reactjs/react-php-v8js
它使用PHP呈现服务器端的UI组件。
It renders react UI components on the server-side with PHP.
实现非常简单,唯一的要求是您需要能够在服务器上设置 V8Js PHP扩展。
The implementation is very simple and the only requirement is that you need to be able to setup the V8Js PHP extension on your server.
更多推荐
从PHP渲染React组件
发布评论