简体   繁体   English

停止锚标记添加到当前URL

[英]Stop anchor tag adding to current URL

I am using react and trying to have an anchor tag that links to an external website " https://www.google.com/ ". 我正在使用react并尝试使用锚标记链接到外部网站“ 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/ " . 但是,如果我在根“localhost:3000”中并单击第二个标记,则会将URL附加到当前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. 如果我导航到我的应用程序“localhost:3000 / example”中的另一个页面,然后单击标签,它将没有任何问题地进入外部链接。

I have tried trimming the start of the URL to get rid of any unwanted "/" but it does not work. 我已经尝试修剪URL的开头以摆脱任何不需要的“/”,但它不起作用。

This is the code I am using 这是我正在使用的代码

<a href={newAddress}>{contactUsButton}</a>);

You can use this 你可以用它

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM