2

Here is my <img> tag

  <li className="dropdown user user-menu">
                                <a href="#" className="dropdown-toggle" data-toggle="dropdown">
                                    <img src="/public/assets/images/user2-160x160.jpg" className="user-image" alt="User Image" />
                                        <span className="hidden-xs">Alexander Pierce</span>
                                </a>
<li/>

This is my structure

enter image description here

shivlal kumavat
  • 868
  • 1
  • 12
  • 28

3 Answers3

3

Import the image at the top as you would any other module! ( assuming you got modules enabled in typescript and then just pass it is as a variable to jsx:

import myimage from "./../.../path/images/user2-160x160.jpg";
...

 <img alt="media-icon-link" className="media-icon-link" src={myimage} />
rtviii
  • 807
  • 8
  • 19
1

If your images are in the public folder Like my folder structure :

"/assets/images/user2-160x160.jpg"

in your <img> src instead of importing

'../../public/assets/images/user2-160x160.jpg'; 

This will work

<img className="user-image"  src="/assets/images/user2-160x160.jpg" alt="User Image" />
shivlal kumavat
  • 868
  • 1
  • 12
  • 28
-1

Same with above answer, As far as I know you can use require api like this

<img alt="media-icon-link" className="media-icon-link" src={require("./../.../path/images/user2-160x160.jpg")} />

It's just depends on your taste

Stark Jeon
  • 1,107
  • 9
  • 24