I found out how to change the starting path in my app for the production build using the "homepage" setting in the package.json.
"homepage":"http//server-name/MyApp"
For this to work I also had to change my routes (using react-router) to include the subdirectory:
<Route path="/MyApp" components={App}>
This works great in prod but when I run npm start during development, I have to manually add "MyApp" to the url. Is there any way I can set this so it npm start runs the app as follows:
http://localhost:3000/MyApp
Thanks!
We might implement this鈥攕ee https://github.com/facebookincubator/create-react-app/pull/1887 for work in progress on this.
But until this is done you have a workaround that will work in both development and production:
<Route path={process.env.PUBLIC_URL} components={App}>
The string will be empty in development, and the /MyApp path in production. You can also concatenation it with other routes.
With React Router 4 you can even make this simpler by specifying basename: https://github.com/facebookincubator/create-react-app/pull/2668.
Most helpful comment
We might implement this鈥攕ee https://github.com/facebookincubator/create-react-app/pull/1887 for work in progress on this.
But until this is done you have a workaround that will work in both development and production:
The string will be empty in development, and the
/MyApppath in production. You can also concatenation it with other routes.With React Router 4 you can even make this simpler by specifying basename: https://github.com/facebookincubator/create-react-app/pull/2668.