I am working on a website at the URL ibd.la. The source can be found on GitHub here.
The website uses React Router to render inner components based on the URL. I was getting 404s when navigating to URLs, but based on advice found on this forum, I have created the file
public/redirects and populated it with this content:
/* /index.html 200
The issue I am seeing now is, if I navigate to a URL (e.g. https://ibd.la/about), the
/about will be removed from the URL, and I will just get to the home page. Any idea why this would be happening, and what can be done to fix it? It’s worth noting this happens on the non-custom domain as well, see here.
The redirect rule
/* /index.html 200 will effectively serve the
index.html no matter what URL the browser requests. To fix, you’ll need to remove this rule and continue to debug the root cause of the 404s.
Let us know if you need help with that!
The cause of the 404s is that without setting up the redirect rule, netlify tries to serve the content at that page which doesn’t exist.
So is there a different way to get the urls to work without having them removed?
Ok, it turns out that the issue was actually my fault. Netlify wasn’t removing the redirect, rather I had a useEffect that set the default URL to ‘/’ regardless of what was already in the URL. I have now fixed this, here’s the commit if this could possibly help anyone: Fix bug with rerouting URL · misingnoglic/ibd.la@d7e51b9 · GitHub