1

After deploying my create-react-app to its own subdomain (contents of the build directory copied to root), the app runs perfectly except upon reloading the page, when it throws a 404 error.

I set the "homepage" property in package.json to its subdomain, ie., "http://sub.domain.com". I also tried setting homepage to ".", and even removing it altogether.

Might this have to do with how subdomains are configured on my host?

1 Answer 1

1

suppose you have a node.js backend. In your routes file define a handler that will serve all the 'unmatched' paths(must be the last one):

 //other routes go here

app.get('*', function (request, response){
//in here just send the index.html
  response.sendFile(path.resolve(__dirname, './frontend/public', 'index.html'))
});
Sign up to request clarification or add additional context in comments.

4 Comments

No node.js backend. It's served from a typical hosting service running apache.
well hope you get the main idea
You need to configure Apache to serve index.html for all unrecognised paths, and not just for the root. Search for "Apache single page applications".
That was it. Thank you Dan!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.