After running Create React App's
npm run build
The generated files are supposed to be served from a web server. When you run
npm run build, you should see the instructions on starting a simple local web server in that directory. If you deploy this directory to a real web server and serve
index.html from the root, it will also work fine.
If the generated file referenced scripts without
/, your site would break as soon as you add client side routing. For example, if an app is located at
mysite.com but also handles a URL like
mysite.com/about, relative paths would cause scripts to be loaded from
mysite.com/about/*.js which would be a 404 error. This is why all paths start from root by default.
If you want to serve your app from a subdirectory (from example
myuser.github.io/myproject), you will need to add
"homepage" field in your
package.json, for example:
Create React App will infer the correct root path based on the
homepage setting. This feature is available since
Please read the deployment instructions for more information.