404 when trying to enter a react app route

后端 未结 1 1230
醉话见心
醉话见心 2020-12-06 22:51

I just deployed my react app build on c-panel. The app includes different routes and everytime I try to get to one of them I get 404 Not found. For example if I

相关标签:
1条回答
  • 2020-12-06 23:24

    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:

    1. Add a custom 404 page which redirects you to index.html.
    2. If your hosting solution, c-panel, provides an error page setting for the deployment, provide index.html as the error page.
    3. 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.

    0 讨论(0)
提交回复
热议问题