0

I have folder structure like:

images here

I have 2 code:

  1. components > cards.js

<img src="path here" />

  1. App.css

background-image: url("./images/img-1.jpg");

questions. Why the example 1 can access the public folder while 2 can't?

1
  • need more info about your question, it is not well explained. Thanks Commented Sep 1, 2021 at 8:15

1 Answer 1

1

Because the path url("./images/img-1.jpg") is a relative file, not a url. Change it to url("/images/img-1.jpg") or url("<base_href>/images/img-1.jpg") if you're behind a reverse proxy.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, I just try your answer; but the error still the same. Error: Can't resolve '/images/img-2.jpg'
As a runtime console error or a build error?
I just noticed you have two image folders. Is img-1.jpg in src/images/ or public/images/?
My bad, just imagine the src/images doesnt exist. I dont know which error is it. Like I try to access 1 image; 1.access from js file 2.access from css file..
How do you get the error to prompt? Do you get it on npm start or when visiting the site you see it in console logs?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.