2

I am using <Link> component of Next.js Link from 'next/link';

I like to make something as <Link href={link} target="_blank"> with same behaviour as <a href={link} target="_blank"> (redirect to new tab). Unfortunately, <Link> does not have target property.

How can I create <Link> to the new tab without closing the current tab?

P.S. I need it because I have a huge table that loads a lot of time, so if I just using <Link> with no new tab, every time client likes to go back he needs to wait 30 seconds.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
ChilTest
  • 461
  • 5
  • 18
  • Does this answer your question? [How to open a link in a new Tab in NextJS?](https://stackoverflow.com/questions/65632698/how-to-open-a-link-in-a-new-tab-in-nextjs) – Hassan Imam Jun 03 '21 at 13:08
  • No, because I will link to an internal link, not an external one as shown in your example. – ChilTest Jun 03 '21 at 13:20

3 Answers3

5

As @adrian suggested in his comment The solution is to use passHref and add target="_blank" to the anchor element:

<Link href="/some/internal/path" passHref>
  <a target="_blank">Your link</a>
</Link>
a.barbieri
  • 2,398
  • 3
  • 30
  • 58
4

<Link> component is use for client navigation (without reloading the app).

If you want to open in a new tab, you can use <a href={url} target="_blank" /> directly without using next/link components, since you are open a new instance of your app / webpage anyway.

Someone Special
  • 12,479
  • 7
  • 45
  • 76
1

I need it because I have a huge table that loads a lot of time, so if I just using <Link> with no new tab, every time client likes to go back he needs to wait 30 seconds.

It isn't possible to open a link in a new window while simultaneously making that link just do internal routing within the app.

You have to load the app fresh if you want to open it in the new window, and that means using <a href={link} target="_blank"> and having the performance impact of reloading the app.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335