4

With Firebase Hosting, when you deploy an app you are asked whether to rewrite all urls to /index.html. This means react-router routes would be properly fired whether they are accessed directly or navigated to from the homepage.

We use Create-react-app and Create-react-app-buildpack to deploy to Heroku. How can we rewrite all the URLs to /index.html in the same manner?

Following this issue, explaining about the routes directive, I configured a static.json in the root to no avail:

{
  "routes": {
    "/images/*": "/images/",
    "/legal/*": "/images/",
    "/media/*": "/media/",
    "/fav/*": "/fav/",
    "/styles/*": "/styles/",
    "/**": "index.html"
  }
}
Guy
  • 12,488
  • 16
  • 79
  • 119
  • You can use an utility like serve to help you with it. https://vijayt.com/post/deploying-react-app-heroku/ – vijayst Jan 29 '18 at 14:38
  • You can also use this hack with `http-server` https://github.com/http-party/http-server/pull/513/files – alayor Sep 28 '19 at 23:39

1 Answers1

5

Create a static.json file in the project root with the following content:

{
  "root": "build/",
  "routes": {
    "/**": "index.html"
  }
}

More here.

haxpanel
  • 4,402
  • 4
  • 43
  • 71