据我了解,React.js 不利于 SEO。我想让我的主页静态化,并且不让 React 参与渲染它,这样我就可以优化它,使其尽可能对 SEO 友好。最好的方法是什么?
最佳答案
您需要使用server side rendering ,它利用 React renderToString
方法,需要动态 Web 服务器。 Here's a tutorial.
renderToString()
Render a React element to its initial HTML. This should only be used on the server. React will return an HTML string. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.
If you call ReactDOM.render() on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.
关于javascript - 如何在仍然使用 React 的情况下制作静态主页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44961331/