Search code examples
javascripthtmlcssreactjslocation-href

open external URL but opens localhost:3000/www.google.com


I am trying to open an external URL , but instead of opening www.google.com in a new tab , it opens http://localhost:3001/www.google.com

<IconButton key={index} size="large" color="primary" href={e.url} target={"_blank"} aria-label="menu" style={{zIndex:100}} >
 <img style={{width:'30px', height:'30px', maxHeight:'30px', maxWidth:'30px'}} href={e.url} target="_blank"
   src={icon}/>
   </IconButton>

Solution

  • Try adding 'https://' to the start of the url to make it an absolute URL - without that it thinks that it is a link relative to the current URL.