Fix 404 Error When Using React-Router-Dom & Nginx

You've got your react application built and deployed to production, but react-router-dom isn't playing nicely and you are seeing 404 pages when loading your routes directly. In this article, we'll help you fix the issue.
Update Nginx Configuration File
To fix this, you need to make a small change to your Nginx configuration files.
Open your Nginx configuration file (replace the highlighted text with the name of your file):
$ sudo nano /etc/nginx/sites-available/default
And change the location section to the following:
location / {
try_files $uri /index.html;
Everything else can be kept the same. Save and close the file when you are finished.
Next, test to make sure that there are no syntax errors in any of your Nginx files:
$ sudo nginx -t
If no problems were found, restart Nginx to enable your changes:
$ sudo systemctl restart nginx
Go to your website and view your changes. You should be able to reload each of your URL routes and the issues you were experiencing should be gone.
Thanks for reading and happy coding!