![]() So to fix your site on Heroku hosting add a file called “static.json” to your root folder (next to packages.json) with the following configuration. The default root document in create-react-app aps is index.html I am using create-react-app, not ejected, with Redux, and making API calls using Redux Sagas. ![]() This does not work once deployed to Heroku. The heroku build pack deploys your site on heroku as a static react application so you have to tell heroku that for ALL routes, it should just go to your root/index document so react-router can handle the application routing. This requires the component to look at the window.pathname, check if a displayed entry is on the Redux state, and if it is not, make an API call to get it and put it on state. If you use react router you will get a 404 from nginx when you try to directly open a route. This tutorial offers a simple way to set up an API that can be quickly updated and tested while creating a React application. This is magic but there is still some configuration needed on your application for routing. In this article we will cover how to create a React application using React-Router for routing and an Express backend. For swyx, and anyone else having the same. You can basically deploy in 2 minutes.Īssuming you have the heroku command line tool already configured the following gist describes the commands to setup the build pack: I actually came across this post first before 3 hours of searching through react-router and heroku documentation. The community have put together a build pack for create-react-app. ![]() I’ve been putting together a React app and I needed cheap, fast hosting so I went to put it on Heroku. Follow me on twitter for more posts like this
0 Comments
Leave a Reply. |