How do I rewrite all urls to index.html in Heroku?

后端 未结 1 1981
后悔当初
后悔当初 2021-01-16 15:47

My Heroku app is using React with React Router. I use Switch to navigate through different components, so the URL changes as well (e.g. /room/4141). However, if

相关标签:
1条回答
  • 2021-01-16 16:22

    That buildpack can be configured via a JSON file:

    You can configure different options for your static application by writing a static.json in the root folder of your application.

    One of the sample routing configurations looks like it does exactly what you want:

    When serving a single page app, it's useful to support wildcard URLs that serves the index.html file, while also continuing to serve JS and CSS files correctly. Route ordering allows you to do both:

    {
      "routes": {
        "/assets/*": "/assets/",
        "/**": "index.html"
      }
    }
    
    0 讨论(0)
提交回复
热议问题