132 words
1 minute
Routing React Apps hosted on Netlify

React is a single page application which means all web pages are served from the same location(index.html). A standard html site would have a separate index file for each page that would be served by the server. Since this isn’t the case for React, you need to create a _redirects in order to get your routes working.

The _redirects file is a file that tells Netlify where it should redirect the clients based on the address or route that they are attempting to request. Our React router takes care of all the routing so all we need to do is have Netlify redirect any request to index.html.

Code#

  1. Create a file named _redirects inside of your public folder, there is no file extension.
  2. The code for the file
/*    /index.html   200
  1. Rebuild and deploy your project
  2. Test it out!
Routing React Apps hosted on Netlify
https://edwardbeazer.com/posts/routing-react-apps-hosted-on-netlify/
Author
Edward Beazer
Published at
2019-01-02