Skip to content

fetching index.html instead of env.js in non-root routes #2

Description

@pmacaluso3

Hi Jese, thank you for writing this package! I am teaching a coding bootcamp, and I am having my students use this to manage their env vars locally and on heroku. We are also using react-router-dom for routing and navigation. (I am not an experienced react or webpack developer, so please tell me if I am doing anything silly!)

I've noticed that when navigating to a route other than root, the <script id="react-dotenv" src="./env.js"></script> tag makes a request to the relative route hostname/yourCurrentRoute/env.js
image

And the server fulfills this request with index.html, which of course blows up
image

I've been working around it by adding "homepage": "" to my package.json, so that the #react-dotenv tag in my index.html gets a src of "/env.js" instead of "./env.js". This seem to fix the issue, as the request uses an absolute route and always goes to hostname/env.js, no matter the route of my react app. Should "" be the default for homepage instead of "."?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions