import React from "react"; import { NavLink, NavLinkProps, To } from "react-router-dom"; import classNames from "classnames"; type Props = { to?: To; children: React.ReactNode; disabled?: boolean; className?: string; } & Omit; function getURL(to: To): URL { if (typeof to !== "string") { return getURL(to.pathname ?? ""); } try { return new URL(to as string); } catch { let outurl = `${window.location.origin}${ to.startsWith("/") ? to : "/" + to }`; return new URL(outurl); } } export default function Link({ to, children, disabled, className, style, ...props }: Props) { const link = to && getURL(to).hostname === window.location.hostname ? ( {children} ) : ( {children} ); return
{link}
; }