简体   繁体   English

SEO友好的React-Redux应用程序

[英]SEO-friendly React-Redux app

React apps render components on the fly, dynamically, so it makes it impossible for search engines to index pages, and complicates social sharing. React应用程序动态地呈现组件,因此它使搜索引擎无法对页面编制索引,并使社交共享变得复杂。 What is the best practice to handle such issues, and make a React-Redux app SEO-friendly? 处理此类问题的最佳做法是什么,并使React-Redux应用程序对SEO友好?

We Need Server-Side Rendering to do SEO for a React App! 我们需要服务器端渲染来为React App做SEO!

Let's split up the application's architecture into three parts: an API server that provides data, a web server that will share code with the client-side and also render HTML, and finally the client ie the code that gets run in the browser. 让我们将应用程序的体系结构分为三个部分:一个提供数据的API服务器,一个与客户端共享代码的Web服务器,还提供HTML,最后是客户端,即在浏览器中运行的代码。

Basically, Server-Side Rendering will allow part of your code to be ran on your web server first. 基本上,服务器端呈现将允许您的部分代码首先在您的Web服务器上运行。 This means the server will first obtain the data from your API that is needed to render on the initial page's HTML, and then it will package and send this data to the client as HTML. 这意味着服务器将首先从您的API获取在初始页面的HTML上呈现所需的数据,然后它将打包并将此数据作为HTML发送到客户端。

After the client gets the initial page HTML and the required data, it will continue the whole JavaScript rendering business, but it already has all the required data. 在客户端获取初始页面HTML和所需数据后,它将继续整个JavaScript呈现业务,但它已经拥有所有必需的数据。 So, using the small example above, a client-side rendering SPA would have to start from scratch, but a server-side rendering SPA would be at a starting point where they already have all the data. 因此,使用上面的小例子,客户端渲染SPA必须从头开始,但服务器端渲染SPA将处于他们已经拥有所有数据的起始点。 Thus, this solves the SEO and slow initial loading problems that SPAs share). 因此,这解决了SEO和缓慢的SPA初始加载问题。

This seems like a rather intuitive idea, but it was only taken more seriously when React came out, since React allows you to do server-side rendering in an elegant manner. 这似乎是一个相当直观的想法,但是当React问世时,它才更加认真,因为React允许您以优雅的方式进行服务器端渲染。

To sum up, server-side rendering can be broken down into 3 steps: 总而言之,服务器端呈现可以分为3个步骤:

(1) Obtain the data needed to render the initial loading page. (1)获取渲染初始加载页面所需的数据。

(2) Render the HTML using this data. (2)使用此数据渲染HTML。

(3) Package the HTML and send it to the client side. (3)打包HTML并将其发送到客户端。

For more follow this link: 有关更多信息请点击此链接

https://www.codementor.io/reactjs/tutorial/redux-server-rendering-react-router-universal-web-app https://www.codementor.io/reactjs/tutorial/redux-server-rendering-react-router-universal-web-app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM