how to override the servers default 404 error message with react app

Viewed 53

I was hosting my react app on a shared server. And I found out there is a bit of disagreement about what to do with URL's between the apache server itself and my app. I will demonstrate what I mean.

so in my react app I have a route like this.

<Route path="/pages" exact render={(props) => (<Pages {...props} />)}/>

And this works perfectly as long as you are in the react app. So in the 'mydomain/' url if you press a button that will link you to the '/pages' url a specific component is loaded because the react app knows what that is supposed to be. But if you directly go to search bar and type "mydomain/pages" and press enter it isn't the react app that is going to decided what to do like it would in a server started with npm start, but the rather the apache server decides what to do, and because there is no physical (index.php/html or any) file in the mydomain/pages the server returns 404 error. I totally understood what the problem is, but I couldn't think of a solution. What can I do to make the react app respond to url changes in that domain rather than the apaches server it self. Thanks!

If you want to check the website I was talking about here is a link.

0 Answers
Related