2022-07-17 21:40:41 +08:00
|
|
|
/* eslint-disable jsx-a11y/anchor-has-content */
|
|
|
|
import Link from 'next/link'
|
2022-10-07 13:55:39 +08:00
|
|
|
import { AnchorHTMLAttributes, DetailedHTMLProps } from 'react'
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2022-10-07 13:55:39 +08:00
|
|
|
const CustomLink = ({
|
|
|
|
href,
|
|
|
|
...rest
|
|
|
|
}: DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>) => {
|
2022-07-17 21:40:41 +08:00
|
|
|
const isInternalLink = href && href.startsWith('/')
|
|
|
|
const isAnchorLink = href && href.startsWith('#')
|
|
|
|
|
|
|
|
if (isInternalLink) {
|
|
|
|
return (
|
|
|
|
<Link href={href}>
|
|
|
|
<a {...rest} />
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAnchorLink) {
|
|
|
|
return <a href={href} {...rest} />
|
|
|
|
}
|
|
|
|
|
|
|
|
return <a target="_blank" rel="noopener noreferrer" href={href} {...rest} />
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CustomLink
|