Files
NotionNext/components/SmartLink.js
anime 7f43846e33 feat: add DOM props filtering for SmartLink component
- Introduce filterDOMProps utility to exclude Next.js specific props
- Apply filtering to external links to ensure clean DOM attributes
- Maintain consistent prop passing for internal Next.js links
2025-07-24 16:43:21 +08:00

37 lines
692 B
JavaScript

import Link from 'next/link'
import { siteConfig } from '@/lib/config'
// 保留允许传给 <a> 的属性
const filterDOMProps = (props) => {
const {
passHref,
legacyBehavior,
...rest
} = props;
return rest;
};
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'
{...filterDOMProps(rest)}>
{children}
</a>
)
}
return (
<Link href={href} {...rest} >
{children}
</Link>
)
}
export default SmartLink