If your application is working for all the routes when you navigate using <Link>
and history.push
but throwing 404 Not Found when you type a URL other than http://example.com, say http://example.com/articles, directly in your browser, you need to:
Teach your server to handle 404s by redirecting to the
index.html page.
You can do this in one of the following ways:
- Add a custom 404 page which redirects you to index.html.
- If your hosting solution, c-panel, provides an error page setting for the deployment, provide index.html as the error page.
- Use HashRouter from react-router. Check HashRouter Solution and What’s HashRouter.
Also, check notes-on-client-side-routing and How to deploy on cPanel.