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?

Mark Salvatore
  • 628
  • 1
  • 7
  • 13

1 Answers1

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'))
});
kurumkan
  • 2,635
  • 3
  • 31
  • 55