Redirects using create react app

Hey Guys,

My Web app is this below.

I’m new as react developer and I’m trying to build my custom error page using the redirects on the react docs and I few videos on the youtube, but is not working.

I’m deplying using the the github through the netlify trigger.

Maybe I’m putting on the wrong folder I will explain better.

Inside the public folder I have the netlify.toml,404.html and inside the netlify.toml has
[[redirects]] from = "/*" to = "/error" status = 404

On the 404.html has a script tag <script type="text/javascript"> window.location.href = window.location.origin + "/error"; </script>

On the src/pages/error.js has component error.js.

My app works but when I put anything after the “/” looks like is trying to refresh the page on a infinite loop.

I don’t have any clue what I am doing wrong.

Thanks
Neto

As mentioned in the File based configuration documentation, a netlify.toml file should go at the root of the repository. A _redirects file as mentioned in the Static routing overview goes in the publish directory—which in the case of React means putting it in the public directory.

For an SPA like React, especially if using React Router, you will generally want a single rule as outlined in [Support Guide] Direct links to my single page app (SPA) don't work
netlify.toml

[redirects]
  from = "/*"
  to = "/index.html"
  status = 200

_redirects

/*    /index.html    200

Man you saved my life hahahah.

I was reading and reading the docs but it wasn’t clear as you mentioned it.

Thanks so much!!

I didn’t realize that I had to include in the _redirects just that lile /* /index.html 200 would take care of everything. I believe any page would work with just that line.

Thanks again.
Neto Sena

Hi @NetoSena :wave:t6:,

Thanks for coming back and letting us know you resolved your issue!