Home > Net >  Relative path in dev incorrectly translated in staging
Relative path in dev incorrectly translated in staging

Time:01-03

I have this situation in React that in development I point to a logo in footer with a relative path wchich is:

import logo from "../../public/assets/images/logo-white.svg";

And this path is not working on the staging server, after debugging i found out that the assets part is missing in the path, in devtools the path is:

/images/logo-white.svg?49346bf607b2345c88562df1dde21b97

when I add the assets part before slash it works, I cannot use absolute path in component and I don't know what can I do to fix it.

CodePudding user response:

You could use it like this for production: process.env.PUBLIC_URL '/images/logo-white.svg'

You can find the detailed documentation on when and how to use the public folder in the React docs

  • Related