24 lines
488 B
TypeScript
24 lines
488 B
TypeScript
import Link from 'next/link'
|
|
import { type ComponentProps, type PropsWithChildren } from 'react'
|
|
|
|
export type Props = ComponentProps<typeof Link>
|
|
|
|
export default function HybridLink({
|
|
href,
|
|
children,
|
|
...rest
|
|
}: PropsWithChildren<Props>) {
|
|
if (href && (typeof href !== 'string' || href.startsWith('/')))
|
|
return (
|
|
<Link href={href} {...rest}>
|
|
{children}
|
|
</Link>
|
|
)
|
|
else
|
|
return (
|
|
<a href={href} {...rest}>
|
|
{children}
|
|
</a>
|
|
)
|
|
}
|