how to redirect routes in Netlify using vite and react?

Viewed 555

I need to redirect to the home of a react project on Netlify but I'm using vite.

I used to do it using CRA (create-react-app) and creating the _redirects file in the public folder with this configuration.

/*  /index.html 200

How would I do it in vitejs?

3 Answers

Try creating a netlify.toml file in root directory.

in netlify.toml

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

You could create the same _redirects file in the root and then modify build script to add it to dist folder like below

  "build": "vite build && cp ./_redirects ./dist/_redirects",
Related