Iggy's Pop
Iggy's Pop

Reputation: 599

can access url by navigating website but not if entering direct url - Netlify

I have deployed a react app to Netlify and if I navigate via the navbar I can access everything and it all works fine. If I however type something like https://example.com/contact I get a not found error. I am using react-router-dom for navigation. Is there something I have to do on the Netlify side or React to fix this?

page not found - Looks like you've followed a broken link or entered a URL that doesn't exist on this site.

Upvotes: 2

Views: 1267

Answers (2)

Rodolfo Campos
Rodolfo Campos

Reputation: 319

Its because your react app is a SPA (Single page application) so you just have a one HTML document so when you type /contact will not find your HTML called "contact" so you need to redirect your app to your HTML page, here is a tutorial that you can follow up

link: https://www.freecodecamp.org/news/how-to-deploy-react-router-based-app-to-netlify/

Upvotes: 3

Pope Francis
Pope Francis

Reputation: 587

To fix this issue create a rewrite rule in the build folder.

  • create a new file with the file name: _redirects with no file extension.
  • add /* /index.html 200 rebuild and publish your file

Upvotes: 0

Related Questions