【问题标题】:On deploying a react redux app to heroku why do we add static.json at root在将 react redux 应用程序部署到 heroku 时,为什么我们要在根目录添加 static.json
【发布时间】:2018-11-03 09:00:29
【问题描述】:

为什么我们要在根目录的 static.json 文件中添加这个 =>

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

【问题讨论】:

    标签: reactjs heroku redux


    【解决方案1】:

    static.json 文件在部署期间与heroku-buildpack-static 一起使用,与heroku 一起用于处理静态站点和单页网络应用程序。

    可以在static.json 中配置许多选项。其中

    Root 允许您为应用程序的目录指定不同的资产根。默认为public_html/

    自定义路线

    您可以定义组合到单个文件的自定义路由。这允许您保留单页 Web 应用程序的路由。支持以下运算符:

    * 支持 URL 中的单个路径段。在下面的配置中,/baz.html 会匹配,但/bar/baz.html 不会。

    ** 支持 URL 中的任意长度。在下面的配置中,/route/foo/route/foo/bar/baz 都可以工作。

    {
      "routes": {
        "/*.html": "index.html",
        "/route/**": "bar/baz.html"
      }
    }
    

    在提供单页应用程序时,支持提供 index.html 文件的通配符 URL 非常有用,同时还能继续正确地提供 JS 和 CSS 文件。路线排序允许您同时执行以下操作:

    {
      "routes": {
        "/**": "index.html"
      }
    }
    

    通过上述配置,您的服务器将为所有路径返回index.html,并且任何路由都在client sidereact-router 上完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 2022-08-10
      • 2018-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多