1

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

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.