1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/components/Link.tsx
2023-08-09 14:30:26 +00:00

39 lines
1.0 KiB
TypeScript

import NextLink from 'next/link'
import { ComponentProps } from 'react'
const { NODE_ENV } = process.env
type Props = { locale?: string; disableClientTransition?: boolean } & ComponentProps<'a'>
export function Link(props: Props) {
const { href, locale, disableClientTransition = false, ...restProps } = props
if (!href && NODE_ENV !== 'production') {
console.warn('Missing href on Link')
}
const isExternal = href?.startsWith('http') || href?.startsWith('//')
if (disableClientTransition) {
return (
/* eslint-disable-next-line jsx-a11y/anchor-has-content */
<a
href={locale ? `/${locale}${href}` : href}
rel={isExternal ? 'noopener' : ''}
{...restProps}
/>
)
}
return (
<NextLink
href={locale ? `/${locale}${href}` : href || ''}
locale={locale || false}
passHref
legacyBehavior
>
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a rel={isExternal ? 'noopener' : ''} {...restProps} />
</NextLink>
)
}