Files
NotionNext/components/SmartLink.js
anime fc4817e669 feat: add SmartLink component for internal and external links
The component automatically detects link type and applies appropriate
rendering with proper attributes for external links.
2025-07-24 16:38:55 +08:00

28 lines
516 B
JavaScript

import Link from 'next/link'
import { siteConfig } from '@/lib/config'
const SmartLink = ({ href, children, ...rest }) => {
const LINK = siteConfig('LINK')
const isExternal = href.startsWith('http') && !href.startsWith(LINK)
if (isExternal) {
return (
<a
href={href}
target='_blank'
rel='noopener noreferrer'
{...rest}>
{children}
</a>
)
}
return (
<Link href={href} {...rest}>
{children}
</Link>
)
}
export default SmartLink