Reputation: 97
Is there a way to open a link in a new tab using Link Next.Js component without using the a tag ? I have tried the following but it did not work with me
<Link target="_blank" href={URL}></Link
The above code still opens the link at the same page.
I have also tried this
<Link href={URL}>
<a target="_blank"></a>
</Link>
this one gave me an error too "Multiple children were passed to with href
"
so is there a way around for that ?
Upvotes: 2
Views: 10073
Reputation: 8412
In your code sample:
<Link href={URL}>
<a target="_blank"></a>
</Link>
You've got error: Multiple children were passed to with href
So it's very likely that you are having some extra spaces between your <Link/>
and <a/>
tag. Double-check that or re-format would help.
But Nextjs <Link>
is for internal app navigation, and to take full advantage of Nextjs's prefetch feature and build-in routing
If you don't need it, just use a normal <a>
tag:
<a target="_blank" href={URL}></a>
Upvotes: 4