Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using prerender.io with ReactJS for SEO

I've realized that my ReactJS application using react-router does not have any external links. Search engines do not recognize that the site has a lot of linked content. Prerender.io seems like a good solution to this, but I cannot get it to work for my ReactJS application.

Can prerender.io be used with ReactJS? If not, is there another good way to improve SEO for my site without doing all the rendering server-side?

EDIT: Upon further digging, I realized that the issue here is that react-router uses a "#" by default, and not a "#!". Is it possible to make react-router work with a "#!"?

like image 306
ritmatter Avatar asked Jan 28 '15 02:01

ritmatter


People also ask

How use Prerender IO in React JS?

you just send an API call, get the rendered HTML from prerender.io, and return it to the crawler. If the user agent is not a crawler you can just return the index. html of your SPA so the JS would kick in. As simple as that!

Is React OK for SEO?

Is React good for SEO? React is a JavaScript framework developed to build interactive and modular UIs. SEO is not a design goal of React but content websites built with React can be optimized to achieve better indexing and ranking.

How do I make React App SEO friendly?

They key to make React more SEO-friendly is to make sure Google doesn't require to use Javascript to render the content on the page. That can be achieved by using Sever-Side Rendering (SSR). Section: What is React and how does it affect your SEO?

What is Prerender SEO?

Prerender provides a technical SEO scoring feature built into the rendering process. The scores are displayed in the cached page results, and you can access a detailed breakdown by clicking on a page's score. Our goal ... Written by Raquel Heyman. Updated on : 13 Jul 2022.


1 Answers

Prerender appears to expect real urls, because otherwise you can't serve the cached html to normal people (the hash isn't sent to the server).

When setting up react-router ensure it's using the history mode:

Router.run(routes, Router.HistoryLocation, function (Handler) {

In your server you'll need to ensure that all routes that don't match a static file are served by either sending index.html, or using prerender.

You can search for 'send all requests to index.html {insert server name here}' to find details on this.


It seems that by default prerender only applies in certain situations. Here's an example if you're using the express.js middleware in node.js:

require('prerender-node').shouldShowPrerenderedPage = function(){ return true }

You should be able to figure out similar modifications for other middleware (it'll require a fork in less flexible languages).

like image 179
Brigand Avatar answered Sep 28 '22 07:09

Brigand