in React, Snippet

React apps in subdirectories that use React Router

If you’ve ever deployed your new React app to a subfolder on your server and you’re using React Router you might notice that React Router starts getting all funky and truncates the subfolder name.  This is the expected behavior, albeit something easy to overlook when deploying to a subfolder.  The good news is that there is a pretty straightforward solution: just add a basepath  to your Router and specify the folder name.

Check out the documentation.

For example, I deploy most of my playground apps to, to deploy the Auto9 app I use a subfolder and the resulting URL is

This is what my Router looks like for that app (keep in mind I import my routes from an external file).

Also, keep in the mind that you should have a “homepage” node in your package.json before you a do a build.

Write a Comment