07f791d
ZhenYi
refactor: replace Preact with React imports for improved consistency across components
07f791d
import type { ReactNode } from 'react'
import { navigate, navigationHref } from '@/shared/lib'
export function Link({ to, children, className = '' }: { to: string; children: ReactNode; className?: string }) {
return (
<a
href={navigationHref(to)}
className={`inline-flex min-h-11 items-center justify-center gap-2 px-0.5 text-xs font-medium text-accent-text hover:underline ${className}`}
onClick={(event) => {
if (event.button || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
// 只有同源 http(s) 链接才拦截:外链、mailto/tel 与自定义协议交给浏览器原生行为。
const href = navigationHref(to)
const target = new URL(href, location.href)
if (!/^https?:$/.test(target.protocol) || target.origin !== location.origin) return
event.preventDefault()
navigate(to)
}}
>
{children}
</a>
)
}