An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
How to fix Page Not Found on netlify
Since you are reading this, you surely might have came across the same error as shown in the cover image.
I'm not sure if other static site servers/platforms are all like that, but if you deploy SPA to Netlify you can only navigate from index.html to other pages using Links.Once you refresh or type a URL directly in the address bar you'll get 404.
Why does this error occur?
If your SPA is build with React then React Router handles routing on the client side (browser) when you visit internal page (e.g. http://localhost:3000/about) but once you host your SPA on Netlify (server-side) the routing logic has to be modified because Netlify does not know how to handle the route.
How to fix the issue?
As per the doc, you need to create a file named _redirects in the root folder.You can go to the link mentioned above to know more about it.I'll directly show how to fix it:
- Create a file named _redirects without any extension inside public folder.
- Copy paste the below content in the file
/* /index.html 200
- Push your code and redeploy
Cheers you fixed the broken link!
Original Link: https://dev.to/kapi1/how-to-fix-page-not-found-on-netlify-a4i
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To