From 7f43846e33846abd23801e7601e20014fb91cb7b Mon Sep 17 00:00:00 2001 From: anime Date: Thu, 24 Jul 2025 15:49:36 +0800 Subject: [PATCH] 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 --- components/SmartLink.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/SmartLink.js b/components/SmartLink.js index f2abbc83..c0a6ec79 100644 --- a/components/SmartLink.js +++ b/components/SmartLink.js @@ -1,6 +1,15 @@ import Link from 'next/link' import { siteConfig } from '@/lib/config' +// 保留允许传给 的属性 +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) @@ -11,14 +20,14 @@ const SmartLink = ({ href, children, ...rest }) => { href={href} target='_blank' rel='noopener noreferrer' - {...rest}> + {...filterDOMProps(rest)}> {children} ) } return ( - + {children} )