forked from Hadiismanto11/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLink.tsx
38 lines (32 loc) · 1.01 KB
/
Link.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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>
)
}