fix(link): prevent opening duplicate browser tabs on Tauri, closes #3514 (#3525)

This commit is contained in:
Huang Xin
2026-03-13 00:29:04 +08:00
committed by GitHub
parent f9a3559086
commit b163012488
+10 -2
View File
@@ -6,16 +6,24 @@ interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
title?: string;
}
const isTauri = isTauriAppPlatform();
const Link: React.FC<LinkProps> = ({ href, children, ...props }) => {
const handleClick = async (e: React.MouseEvent<HTMLAnchorElement>) => {
if (isTauriAppPlatform()) {
if (isTauri) {
e.preventDefault();
await openUrl(href);
}
};
return (
<a href={href} target='_blank' rel='noopener noreferrer' onClick={handleClick} {...props}>
<a
href={href}
target={isTauri ? undefined : '_blank'}
rel='noopener noreferrer'
onClick={handleClick}
{...props}
>
{children}
</a>
);