In my experience, webpack will replace process.env.PUBLIC_URL
with a fixed value during build.
So, it may be that you evaluating it, additionaly, causes problems.
Meaning it should be process.env.PUBLIC_URL
in the code, not ${process.env.PUBLIC_URL}
.
E.g., with my package.json looking like this (the homepage setting influences PUBLIC_URL)...
{
"name": "meetup-app",
"version": "0.1.0",
"private": true,
"homepage": "/uvs",
... and this below code in App.js...
function App() {
const basePath = process.env.PUBLIC_URL;
return (
<div className="App">
<Layout>
<Suspense fallback={<p>Loading...</p>}>
<Routes>
<Route path={basePath} exact element={<AllMeetupsPage />}></Route>
<Route
path={basePath + "/new-meetup"}
element={<NewMeetupsPage />}
></Route>
<Route
path={basePath + "/favorites"}
element={<FavoritesMeetupsPage />}
></Route>
</Routes>
</Suspense>
</Layout>
</div>
);
}
... the build output will have this content (I re-formatted it):
("ul", {
children: [(0, u.jsx)("li", {
children: (0, u.jsx)(a.rU, {
to: s,
children: "All Meetups"
})
}), (0, u.jsx)("li", {
children: (0, u.jsx)(a.rU, {
to: "/uvs/new-meetup",
children: "Add New Meetup"
})
}), (0, u.jsx)("li", {
children: (0, u.jsxs)(a.rU, {
to: "/uvs/favorites",
children: ["My Favorites", (0, u.jsx)("span", {className: c, children: e.totalFavorites})]
})
})]
})
(Sorry if this is utter nonsense, I'm a total newbie, only some 2 weeks into front end development.)