File size: 687 Bytes
492326f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import type { ReactNode } from "react";
import { isPlainLeftClick, navigate } from "../lib/router.js";
export type AppLinkProps = {
href: string;
className?: string;
title?: string;
children: ReactNode;
};
/** In-app anchor: real href for middle/modified clicks, SPA navigation otherwise. */
export function AppLink({ href, className, title, children }: AppLinkProps): React.JSX.Element {
const onClick = (event: React.MouseEvent<HTMLAnchorElement>): void => {
if (!isPlainLeftClick(event)) return;
event.preventDefault();
navigate(href);
};
return (
<a href={href} className={className} title={title} onClick={onClick}>
{children}
</a>
);
}
|