On deploying a react redux app to heroku why do we add static.json at root

夙愿已清 提交于 2020-01-15 08:43:08

问题


why do we add this in static.json file at root =>

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

回答1:


static.json file is used with heroku-buildpack-static during deployment with heroku for handling static sites and single page web apps.

A number of options can be configured in static.json. Amongst them

Root allows you to specify a different asset root for the directory of your application. By default it is public_html/

Custom Routes

You can define custom routes that combine to a single file. This allows you to preserve routing for a single page web application. The following operators are supported:

* supports a single path segment in the URL. In the configuration below, /baz.html would match but /bar/baz.html would not.

** supports any length in the URL. In the configuration below, both /route/foo would work and /route/foo/bar/baz.

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

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": {
    "/**": "index.html"
  }
}

With the above configuration, your server will return the index.html for all paths and any routing is done on client side with react-router



来源:https://stackoverflow.com/questions/50504161/on-deploying-a-react-redux-app-to-heroku-why-do-we-add-static-json-at-root

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