newbie
newbie

Reputation: 468

Override root path in ReactJS

When I run my application using npm start, it runs on the root

You can now view my-app in the browser.

  Local:            http://localhost:3000/

I want to change it so it hits index.html using http://localhost:3000/my-app and doesn't directly deploy on the root.

I tried adding the homepage peoperty in package.json but it still runs on the root.

..
"homepage": "https://localhost:3000/my-app",..

Upvotes: 2

Views: 2722

Answers (1)

Nathan
Nathan

Reputation: 8149

Maybe you can try changing your process.env.PUBLIC_URL to point to your my-app directory? The relevant code I see for determining the public url location on react is the following:

const envPublicUrl = process.env.PUBLIC_URL;

...

const getPublicUrl = appPackageJson =>
  envPublicUrl || require(appPackageJson).homepage;

So if your process.env.PUBLIC_URL; is already set, by short-circuit evaluation, your second conditional statement: require(appPackageJson).homepage; will not be evaluated. So perhaps your homepage key is not even being evaluated from within your package.json file. For more information on setting/getting node's process.env variables check out this tutorial

Hopefully that helps!

Upvotes: 2

Related Questions