{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
I need to open that link in new tab. how to do it? i have tried this.
But its not working. |
Beta Was this translation helpful? Give feedback.
Replies: 5 suggested answers 18 replies
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
EDIT: See the response from @Tylerian below.
|
Beta Was this translation helpful? Give feedback.
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
Simply put your navigation code inside an anchor with _blank as target (i.e: <a herf={`/product-details/${product.id}`} target="_blank">). Using Link component here provides no performance benefit to the end user since you're requesting a fresh load of your site on a new browser tab. |
Beta Was this translation helpful? Give feedback.
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
Create a Anchor component. // Anchor.styles.ts
import styled from 'styled-components'
export const Anchor = styled.a`
color: inherit;
height: fit-content;
text-decoration: none;
width: fit-content;
:visited,
:hover,
:active {
color: inherit;
}
> * {
color: inherit;
}
` // Anchor.tsx
import Link from 'next/link'
import { ReactNode } from 'react'
type AnchorProps = {
href: string
children: ReactNode
passHref?: boolean
target?: '_blank' | '_self' | '_parent' | '_top'
}
export function Anchor({ href, passHref, target, children }: AnchorProps) {
return (
<Link href={href} passHref={passHref}>
<S.Anchor href={href} target={target}>
{children}
</S.Anchor>
</Link>
)
} Using const render = () => (
<Anchor href="https://example.com/new-page" target="_blank" >
open in new page
</Anchor>
) |
Beta Was this translation helpful? Give feedback.
-
If you want:
You need to follow @Tylerian 's comment: #15486 (reply in thread) and wrap an a tag with a Link tag. <div>
<Link href='/blah' passHref>
<a>
<div>
Component to link
</div>
</a>
</Link>
</div> This seems like a pretty common use case, e.g. all of Vercel's links can be cmd+clicked, and almost every Would it be much effort to add a prop to the Link component, e.g. |
Beta Was this translation helpful? Give feedback.
-
Hi @paambaati @naseef0 @Tylerian @leerob from the release of Next v13, usage of anchor tag Can anybody still tell me, how we can achieve the behavior of opening Link in new tab with the Thanks. |
Beta Was this translation helpful? Give feedback.
EDIT: See the response from @Tylerian below.
Adding thepassHref
prop to your<Link>
component should solve this.Further reading — https://nextjs.org/docs/api-reference/next/link#forcing-link-to-expose-href-to-its-child