Create-react-app: Specifying the starting url path in npm start

Created on 16 Aug 2017  路  1Comment  路  Source: facebook/create-react-app

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!

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:

<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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stopachka picture stopachka  路  3Comments

fson picture fson  路  3Comments

alleroux picture alleroux  路  3Comments

Aranir picture Aranir  路  3Comments

onelson picture onelson  路  3Comments