0

I am using react and trying to have an anchor tag that links to an external website "https://www.google.com/".

I have two instances of this anchor tag in my code.

The first tag is working as expected, the external link is visited without any problem.

However, if I am in the root "localhost:3000" and I click on the second tag, it appends the URL to the current URL "localhost:3000/https://www.google.com/" .

If I navigate to another page in my app "localhost:3000/example" and then click on the tag it will go the external link without any problems.

I have tried trimming the start of the URL to get rid of any unwanted "/" but it does not work.

This is the code I am using

<a href={newAddress}>{contactUsButton}</a>);
Persian
  • 294
  • 2
  • 8
  • 1
    {newAddress} likely misses some part of `https://` or has a leading space - post a view-source – mplungjan Jun 14 '19 at 08:41
  • @mplungjan That was my first thought but I console.log it before it uses it and the URL is correct. This is really strange as the other anchor code is the exact same thing and it works fine. – Persian Jun 14 '19 at 08:43
  • Possible duplicate of [How to make a hyperlink external in react?](https://stackoverflow.com/questions/50350085/how-to-make-a-hyperlink-external-in-react) –  Jun 14 '19 at 08:54
  • 1
    Try adding `target="_blank"` to your anchor tag, and check if it hits to correct URL. – ravibagul91 Jun 14 '19 at 09:27

1 Answers1

0

You can use this

import { Redirect } from 'react-router'
<Redirect to="/your url" />