In this post, we will see how to resolve Why does “Cannot GET” appear when I access the page on google using node, but the route in React works?
Question:
I’m building an application with Reactjs and Nodejs and I’ve built all my routes using React-Router-Dom`
<Link to={}> </Link/>
or I use UseNavigate();
.But I’m having problems when I access the site directly with the link, I’ll show you a picture of when I use the button on the page: Image Here
When I access the same link writing in the browser itself, this message appears to me: Second Image Here
The browser recognizes it as another type of route.
I’m using Nodejs for my Back-End and I really don’t know what to do about it. Can anyone help me, why I don’t know if I can fix it using Reactjs or Nodejs?
Best Answer:
Are you rendering your React build using NodeJS? If so, you’ll have to instruct your backend to always render index.html.You’ll have to do something like this in your server:
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com