I uploaded react.js application to server. I'm using nginx server. Application is working fine. But when I go to other page & refresh, site is not working. It's showing 404 Not found error.
How can I solve this.
Thank You.
I uploaded react.js application to server. I'm using nginx server. Application is working fine. But when I go to other page & refresh, site is not working. It's showing 404 Not found error.
How can I solve this.
Thank You.
When your
react.js
app loads, the routes are handled on the frontend by thereact-router
. Say for example you are athttp://a.com
. Then on the page you navigate tohttp://a.com/b
. This route change is handled in the browser itself. Now when you refresh or open the urlhttp://a.com/b
in the a new tab, the request goes to yournginx
where the particular route does not exist and hence you get 404.To avoid this, you need to load the root file(usually index.html) for all non matching routes so that
nginx
sends the file and the route is then handled by your react app on the browser. To do this you have to make the below change in yournginx.conf
orsites-enabled
appropiatelyThis tells
nginx
to look for the specified$uri
, if it cannot find one then it sendindex.html
back to the browser.