import NextLink , { LinkProps } from 'next/link' ; import { useRouter } from 'next/router' ; import { AnchorHTMLAttributes , forwardRef } from 'react' ; interface Props extends AnchorHTMLAttributes < HTMLElement > { href : string ; newTab ? : boolean ; linkProps ? : LinkProps ; } /**
 * Component for rendering a Next.js link using an anchor tag. This is mostly
 * to allow Next.js to preload routes and for the anchor tag to pass a11y.
 */ export const Link = forwardRef < HTMLAnchorElement , Props > ( ( { children , href , linkProps = { href } , newTab , ... props } , ref ) => { const router = useRouter ( ) ; let newTabProps ; if ( newTab ) { newTabProps = { target : '_blank' , rel : 'noreferrer' , } ; } const linkNode = ( < a href = { href } { ... props } { ... newTabProps } ref = { ref } > { children } < /a>); return linkNode ; if ( router . asPath . includes ( '/search' ) ) { return linkNode ; } return < NextLink { ... linkProps } > { linkNode } < /NextLink>; } ) ;