This guide will help you deploy your React web application on Netlify and fix any navigation errors using a netlify.toml
file.
npx create-react-app my-app
Navigate into your project directory:
cd my-app
git init
git add .
git commit -m "Initial commit"
Create a repository on GitHub and push your project:
git remote add origin https://github.com/your-username/your-repo-name.git
git branch -M main
git push -u origin main
Login to Netlify and create a new site from Git:
- Choose your GitHub repository
- Set the build command to
npm run build
- Set the publish directory to
build
To fix navigation errors (e.g., 404 errors on page refresh), create a netlify.toml
file in the root of your project with the following content:
[build]
command = "npm run build"
publish = "build"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
git add netlify.toml
git commit -m "Add netlify.toml to fix navigation errors"
git push
Go to your Netlify dashboard and trigger a redeploy of your site to apply the changes.
By following these steps, you should have your React web application deployed on Netlify without navigation errors. The netlify.toml
file ensures that all navigation requests are correctly redirected to your index.html
file.