【问题标题】:Configuring a single page Create-React-App on Heroku在 Heroku 上配置单页 Create-React-App
【发布时间】:2023-03-10 18:18:01
【问题描述】:

使用 Firebase 托管,当您部署应用时 you are asked 是否将所有 url 重写为 /index.html。这意味着 react-router 路由将被正确触发,无论它们是直接访问还是从主页导航到。

我们使用Create-react-appCreate-react-app-buildpack 部署到Heroku。我们如何以相同的方式将所有 URL 重写为 /index.html?

this issue之后,解释了routes指令,我在根目录中配置了一个static.json无济于事:

{
  "routes": {
    "/images/*": "/images/",
    "/legal/*": "/images/",
    "/media/*": "/media/",
    "/fav/*": "/fav/",
    "/styles/*": "/styles/",
    "/**": "index.html"
  }
}

【问题讨论】:

标签: reactjs heroku create-react-app buildpack


【解决方案1】:

在项目根目录下创建static.json文件,内容如下:

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

更多here.

【讨论】:

    猜你喜欢
    • 2020-11-26
    • 2017-11-29
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 2017-06-06
    • 2017-12-04
    相关资源
    最近更新 更多