Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can't resolve the image path

Good day guys.

I have a problem in my project related the Not found route. The problem is i have my app hosted on vercel and if you add two routes the image will disappear. For instance, if I would to do baseURL/randomthing – the image will appear, however, if I do baseURL/randomthing/anotherrandomthing the image will disappear. After debbuging I found that the problem is related to the way I import the image.

Code causing error

<img src="./plug-in.png" style={imageStyle} />

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you try to add another "." syntax to the image path ../plug-in.png you will get the image back on the second route and so on.

I tried many things. Any idea why this is happening?

This is the code: github

And this is the app: https://chess-game-gani.vercel.app/

Thanks in advance.

>Solution :

You want to use dynamic paths for your images, for example:

<img src="/plug-in.png" style={imageStyle} />

This is because the path ./ will always try to take the file from the same directory that you are currently in, whereas the path / will always target the root directory of the site.

For example, if you are in the route domain.com/route, the ./ path would look for the image in the domain.com/route/ directory but the path / would look for the image in the domain.com/ directory.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading