你如何使用 React.js 进行 SEO? [英] How do you use React.js for SEO?

查看:35
本文介绍了你如何使用 React.js 进行 SEO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

React.js 上的文章喜欢指出,React.js 非常适合 SEO 目的.不幸的是,我从来没有读过,你实际上是如何做到的.您是否像在 https://developers.google 中那样简单地实施 _escaped_fragment_.com/webmasters/ajax-crawling/docs/getting-started 并让 React 在服务器上呈现页面,当 url 包含 _escaped_fragment_ 时,或者还有更多内容?

Articles on React.js like to point out, that React.js is great for SEO purposes. Unfortunately, I've never read, how you actually do it. Do you simply implement _escaped_fragment_ as in https://developers.google.com/webmasters/ajax-crawling/docs/getting-started and let React render the page on the server, when the url contains _escaped_fragment_, or is there more to it?

能够不依赖 _escaped_fragment_ 会很棒,因为可能并非所有潜在的抓取网站(例如在共享功能方面)都实现 _escaped_fragment_.

Being able not to rely on _escaped_fragment_ would be great, as probably not all potentially crawling sites (e.g. in sharing functionalities) implement _escaped_fragment_.

推荐答案

我敢肯定,您所看到的任何宣传 React 对 SEO 有益的东西都与能够在服务器上呈现请求的页面有关,之前将其发送给客户端.因此,就搜索引擎而言,它将像任何其他静态页面一样被编入索引.

I'm pretty sure anything you've seen promoting React as being good for SEO has to do with being able to render the requested page on the server, before sending it to the client. So it will be indexed just like any other static page, as far as search engines are concerned.

通过ReactDOMServer.renderToString 使服务器渲染成为可能.访问者将收到已呈现的标记页面,React 应用程序将在下载并运行后检测到该页面.当 ReactDOM.render 被调用时,它不会替换内容,它只会添加事件绑定.在接下来的访问中,React 应用程序将接管并在客户端呈现更多页面.

Server rendering made possible via ReactDOMServer.renderToString. The visitor will receive the already rendered page of markup, which the React application will detect once it has downloaded and run. Instead of replacing the content when ReactDOM.render is called, it will just add the event bindings. For the rest of the visit, the React application will take over and further pages will be rendered on the client.

如果您有兴趣了解更多相关信息,我建议您搜索Universal JavaScript"或Universal React"(以前称为isomorphic react"),因为这正在成为使用单一代码的 JavaScript 应用程序的术语在服务器和客户端上呈现的基础.

If you are interested in learning more about this, I suggest searching for "Universal JavaScript" or "Universal React" (formerly known as "isomorphic react"), as this is becoming the term for JavaScript applications that use a single code base to render on both the server and client.

这篇关于你如何使用 React.js 进行 SEO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆