I am trying to issue a server side redirect for certain pages for SEO reasons. The problem I am trying to solve is that some of my pages will get index by google, so if they are deleted or taken offline we want to redirect them to a different page rather than showing 404. What is the best way to achieve such redirects with React Router on the server side(express.js)?
3
Answers
You should have a component which should define routing rules, something like this:
All I am saying is that you should define a wrapper which define the redirect url:
Now add this to your url handling page:
If you are using React Router 4, tou can add
Redirect
component inside your Page component to redirect pages that are dead. Example: Let’s say that component tried to fetch object from API but got an offline response and stored it in component state:in server.js