DEV Community

Bon Tertius Tuyishimire
Bon Tertius Tuyishimire

Posted on

1

How I solved “Page not found” on my react projects deployed on netlify

During my journey after completing learning React, I’ve been working on side projects and I always use React Router for SPA. By the way, I had this issue(below) everytime I deploy them on netlify just when I try to refresh the website or just navigate to the specific path.

Image description

So in this article, I did my research that I'm going to share with you to get over this issue, then navigate your website or SPA without any issues out of your codes

When does it show up

This issue shows up every time you try to refresh your website or anytime you want to navigate through a specific path indirectly, i mean by modifying the address. This issue occurs because netlify, by default, expects server-side routes rather than client-side routes.

How to solve it

So to solve this issue you have to set a redirect rule to netlify. Just go to your project, in which you used react-router, then in your public folder create a file and name it _redirects (without any extension).

Image description

After the creation, just click on that file then write down this line of code.

/* /index.html 200

Image description

Just this rule ensures that all requests are directed to your react application’s entry point, allowing react-router to handle the routing correctly.

Make sure that the _redirects file is placed in the public folder, netlify will automatically recognizes and uses this file during the deployment process to handle custom redirect rules. The file have to be in the version of your project on netlify in order to get detected by netlify.

Follow me for more tips and tricks, HAPPY CODING ;)

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Postmark Image

"Please fix this..."

Focus on creating stellar experiences without email headaches. Postmark's reliable API and detailed analytics make your transactional emails as polished as your product.

Start free

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️