0

<a href={website} target="_blank" rel="noopener noreferrer">
                 <i className="fas fa-globe fa-2x"></i>
               </a>

website = "www.w3school.com"

//output must be http://www.w3school.com

//but i m getting the output combined with localhost link http://localhost:8080/developers/www.w3school.com

1 Answers1

-1

It is treating the link as a relative path, and so it appends the host site to the beginning of the link. If you explicitly declare the protocol (http or https in most cases) it will work fine.

If the value of the website variable is set dynamically, you can check for '//' in the string and append 'http://' if it is not present.

How to add http:// if it doesn't exists in the URL? You can see a function here to accomplish that.

If the variable is going to be set statically, just remember to use the absolute path, including protocol.

Cal Irvine
  • 1,104
  • 8
  • 17