Skip to content

Instantly share code, notes, and snippets.

@belachkar
Last active May 13, 2021 00:03
Show Gist options
  • Save belachkar/c38276848f1717608227cd9df8fde240 to your computer and use it in GitHub Desktop.
Save belachkar/c38276848f1717608227cd9df8fde240 to your computer and use it in GitHub Desktop.

Netlify React SPA Configuration

To avoid 404 error, and to redirect all the requests to index.html

Create _redirects file

create an _redirects file in the root of the deployed folder with the content:

/* /index.html 200

Add redirects to the Netlify configuration file

netlify.toml:

[build]
  # Directory to change to before starting a build.
  # This is where we will look for package.json/.nvmrc/etc.
  # If not set, defaults to the root directory.
  base = "/"
  publish = "build"
  command = "npm run build"

# The following redirect is intended for use with most SPAs that handle
# routing internally.
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment