Home > Software design >  Dynamically need an image redirect to an external url in react
Dynamically need an image redirect to an external url in react

Time:08-08

Here's my code everything is fine but image getting redirected to localhost:3000/www.xyz.com I want it to be redirected to something like www.xyz.com directly without a home directory

{verticalSlide.map( (item) => ( 
<NavLink to={`${item.link}`}  >
<img src={item.image} alt="/"/>
</NavLink>
))}

CodePudding user response:

Don't use NavLink, instead directly open url with help of window object

{verticalSlide.map( (item) => ( 
  <img onClick={() => window.open(item.link, '_blank')} src={item.image} alt="/"/>
))}
  • Related