如何在新标签中打开惯性链接?

发布于 2025-01-30 11:05:57 字数 243 浏览 0 评论 0原文

是否有一种方法可以在新选项卡中打开惯性链接,例如and> Anchor标签:

<a target="_blank" rel="noopener noreferrer"></a>

这不起作用:

<Link :href="..." target="_blank">

Is there a way to open an inertia link in a new tab like it's possible in anchor tags:

<a target="_blank" rel="noopener noreferrer"></a>

This doesn't work:

<Link :href="..." target="_blank">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

总以为 2025-02-06 11:05:57

我不认为这是可能的 - 因此,标准的锚标签是必经之路。

这是因为如果将在新选项卡中打开链接,则惯性不需要真正涉及,因为它不必拦截单击并执行自己的服务器请求。

惯性开发人员在此GitHub问题中确认: https://github.com/inertiajs/inertiajs/inertia/issues/Intia/issues/Issues/Issues/Issues /1096

I don't believe this is possible - so a standard anchor tag is the way to go.

This is because Inertia doesn't really need to be involved if a link will be opening in a new tab, since it doesn't have to intercept the click and perform its own server request.

Confirmed by Inertia's developer in this github issue: https://github.com/inertiajs/inertia/issues/1096

平定天下 2025-02-06 11:05:57

这里似乎有同样的问题
但这是很久以前的
我不确定您现在正在使用哪个依赖项
与问题兼容
但是您可以查看是否对您有帮助
react-router open-router open link in New Tab

Seems to have the same problem here
But it was a long time ago
I'm not sure which dependency version you're using now
is compatible with the issue
But you can see if that helps you
React-Router open Link in new tab

掩饰不了的爱 2025-02-06 11:05:57

尝试以下

JavaScript:

const newTab = (e) => {
    e.preventDefault();
    window.open(route('the_route_you_want'));
}

在组件中:

<Link onClick="newTab">Open new window</Link>

Try the following

Javascript:

const newTab = (e) => {
    e.preventDefault();
    window.open(route('the_route_you_want'));
}

In component:

<Link onClick="newTab">Open new window</Link>
青衫负雪 2025-02-06 11:05:57

@thomas-lo答案确实帮助我解决了这个问题。我只是对其进行了一些修改,以便我们可以在链接onClick事件上修改URL。
定义此功能:

const handleOpenNewTab = (href) => {
    window.open(href, '_blank');
};

在组件中:

<Link
     href="#"
     className="flex items-center"
     onClick={(e) => { e.preventDefault(); handleOpenNewTab('/my/url') }}
>
    print Pdf
</Link>

The @thomas-lo answer really helped me solve the issue. I just modify it a little so we could modify the url on the Link onClick event.
Define this function:

const handleOpenNewTab = (href) => {
    window.open(href, '_blank');
};

and in the component:

<Link
     href="#"
     className="flex items-center"
     onClick={(e) => { e.preventDefault(); handleOpenNewTab('/my/url') }}
>
    print Pdf
</Link>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文