2021-01-12 23:35:36 +08:00
|
|
|
/* eslint-disable jsx-a11y/anchor-has-content */
|
2021-01-09 17:50:45 +08:00
|
|
|
import Link from 'next/link'
|
2023-07-07 11:17:22 +08:00
|
|
|
import { AnchorHTMLAttributes, DetailedHTMLProps } from 'react'
|
2021-01-09 17:50:45 +08:00
|
|
|
|
2023-07-07 11:17:22 +08:00
|
|
|
const CustomLink = ({
|
|
|
|
href,
|
|
|
|
...rest
|
|
|
|
}: DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>) => {
|
2021-01-09 17:50:45 +08:00
|
|
|
const isInternalLink = href && href.startsWith('/')
|
|
|
|
const isAnchorLink = href && href.startsWith('#')
|
|
|
|
|
|
|
|
if (isInternalLink) {
|
2023-07-07 11:17:22 +08:00
|
|
|
// @ts-ignore
|
|
|
|
return <Link href={href} {...rest} />
|
2021-01-09 17:50:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isAnchorLink) {
|
2021-01-10 15:19:00 +08:00
|
|
|
return <a href={href} {...rest} />
|
2021-01-09 17:50:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return <a target="_blank" rel="noopener noreferrer" href={href} {...rest} />
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CustomLink
|