DEV Community

Melvin Kosisochukwu
Melvin Kosisochukwu

Posted on

Deploying React App With Router On Netlify

Netlify has made it easy to deploy react projects for free, amazing right?.
When I first tried to deploy an app with a router I came across a slight obstacle, this was an easily solved issue but at that moment, it was a little hard for me to get through it.
This article is to help the next newbie that might come across such issues.

The solution to getting your routing to work on Netlify lies in one file, the netlify.toml file. This is the netlify configuration file, for mor information on this check here.

All you have to do is create a netlify.toml file in your root folder and inside the file include this code:

Alt Text

This will catch all the redirects and your React app should work just fine.

You can run npm build and manually upload your files or link it to your GitHub/Gitlab/Bithub repository and netlify will handle the continuous integration for your app(i.e all new changes pushed to your repository will be reflected online without you having to rebuild the app)

I hope this article helps someone and if you have any inquiries or questions you can leave a comment, thank you.

Top comments (4)

Collapse
 
xs005 profile image
Chris Sun

React beginner, first time to know this service. Thanks for sharing.

Collapse
 
melvinmanni profile image
Melvin Kosisochukwu

Happy to bring the information across to you 😁.

Collapse
 
alb_isma profile image
ismailalabou • Edited

should i add netlify.toml files in root repo OR the /build directory ??

Collapse
 
melvinmanni profile image
Melvin Kosisochukwu

Root