Need to set the href value for <base href=""/>
tag based on build environment configuration.
Eg:
Staging should have <base href="/staging" />
Prod should have <base href="/" />
Current setup:
Build command:
"build": "sh -ac '. .env.${REACT_APP_ENV}; react-scripts build'",
"build:staging": "REACT_APP_ENV=staging npm run build",
"build:prod": "REACT_APP_ENV=production npm run build",
.env.staging.js:
REACT_APP_BASE_HREF=/staging
index.html:
....
<base href="" + process.env.REACT_APP_API_URL />
....
This doesn't seem to work in index.html. While similar setup works for JS files
(Probably because JS files are parsed and bundled into a single file and the bundler reads the values at that point of time)
Things tried:
index.html:
<base href=process.env.REACT_APP_API_URL />
<base href="process.env.REACT_APP_API_URL" />
<base href="%process.env.REACT_APP_API_URL%" />
(similar to PUBLIC_URL variable)
Setting basename property along with Browser Router also does not solve the problem
This problem was solved. Follow these steps:
homepage
key to ""
PUBLIC_URL=/survey
<base href>
. Can be removed from HTML fileChange links for stylesheet to
<link rel="stylesheet" href="%PUBLIC_URL%/vendor/bootstrap/css/bootstrap.min.css">
No need to add process.env
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With