I am build the react app using the create_react_app. Now i move the build to the server and run the app using npmjs.com/package/serve. My app will load the data from the apis. When i refresh the page it shows 404 page not found error. Also i tried with npmjs.com/package/http-server
When i was some page /dashboard and refresh the page it shows 404. Now i have to go to BASE_URL/ then only it works. But in my local when i refresh everything works.
This is my package.json
"react-dates": "^17.0.0",
"react-dom": "^16.4.0",
"react-i18next": "^7.7.0",
"react-redux": "^5.0.7",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.4"
And i use apache on my server.
I think this is the problem not with my code. If you guys know anything about this, please help me.
You need to force each request to serve the index file. You may want to look into the .htaccess file. In here you can define rewrites that allow each request to be served by the index file. Using the HTML5 History API, React router will know how to correctly render the page.
Zeit's serve also provides setting rewrites in their configuration file. Have a look at the following link: github.com/zeit/serve-handler
Adam Szaloczi
How about the router setup? Do you use Reacr Router, or other router lib? I would looking at that.