Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying the starting url path in npm start #2959

Closed
steveareeno opened this issue Aug 16, 2017 · 1 comment
Closed

Specifying the starting url path in npm start #2959

steveareeno opened this issue Aug 16, 2017 · 1 comment

Comments

@steveareeno
Copy link

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!

@gaearon
Copy link
Contributor

gaearon commented Aug 16, 2017

We might implement this—see #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: #2668.

@gaearon gaearon closed this as completed Aug 16, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants