Search code examples
javascripthtmlreactjsionic-frameworkionic5

img element is not working in Ionic React


A straight forward image element does not seem to work in Ionic React.

I added an image in assets/images folder and gave the relative path in src of image element.

<img src="../../assets/images/image-1.jpeg" alt=""/>

I created a working example using CodeSandbox. Can somebody help me if I was doing anything wrong here?


Solution

  • Figured out the issue here. I had to put the images in assets folder which will be in public folder.

    I moved my local image to public/assets/images/image-1.jpeg and then access that path in img element.

    <img src="assets/images/image-1.jpeg" alt=""/>