Configuring a single page Create-React-App on Heroku

时间秒杀一切 提交于 2019-12-07 07:09:59

问题


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"
  }
}

回答1:


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

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

More here.



来源:https://stackoverflow.com/questions/48503348/configuring-a-single-page-create-react-app-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!