您的位置:首页 > Web前端 > React

react a标签跳转问题

2020-07-18 04:24 3143 查看

react中, 当a标签需要跳转到动态获取的外部链接, 比如:

profile:{
"website":"www.xxx.com"
}
<a
href={profile.website}
target="_blank"
rel="noopener noreferrer"></a>

会跳转到新的标签页,但是地址会是localhost:3000/www.xxx.com,跳转不成功

应该加上http

<a
href={“http://”+profile.website}
target="_blank"
// onClick={()=>window.location.href=`http://${profile.website}`}
rel="noopener noreferrer"></a>

然后你会发现blank就会失效,会一直在当前页打开
最后

<a
href={“http://”+profile.website}
target="_blank"
// onClick={()=>window.location.href=`http://${profile.website}`}
rel="noopener noreferrer external"></a>

就ok了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: