首页 > 解决方案 > 无法导航到 href,url 只是丢失了参数

问题描述

我在 react 中有一个 a 标签,单击它时不会将我带到 href 它只是删除了 url 中的所有参数?例如。我在:http://localhost:6006/iframe.html?selectedKind=Survey&selectedStory=...etc。然后它把我带到http://localhost:6006/iframe.html?点击,而不是 google.com

我也尝试过在单击按钮时使用 window.open ,如果我正常执行 window.open ,那也是一样的。有任何想法吗?

exitUrl = 'https://www.google.com';

target = '_self';

作品

        window.open(this.exitUrl, this.target);

不工作

<a href={this.exitUrl} target={this.target}>

<button onClick={() =>window.open(this.exitUrl, this.target)}

还尝试将锚点的 onclick 设置为相同,但仍然无法正常工作:

let anchor = document.getElementById('wtfisgoinon');
anchor.onclick = window.open(this.exitUrl, this.target);

标签: javascripthtmlreactjsanchorhref

解决方案


如果你想打开它,没有必要使用“目标”属性。

只需使用:

<a href={this.exitUrl}> Exit </a>

推荐阅读