From 4c90885d922baf03007d5bce87c791a200f741b5 Mon Sep 17 00:00:00 2001
From: Maximus <ten.maksim97@gmail.com>
Date: Fri, 9 Sep 2022 18:57:43 +0300
Subject: [PATCH] fixed props in link component

---
 src/components/typography/Link.tsx | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/components/typography/Link.tsx b/src/components/typography/Link.tsx
index 442eeea..d5ac56d 100644
--- a/src/components/typography/Link.tsx
+++ b/src/components/typography/Link.tsx
@@ -1,17 +1,20 @@
 import React from "react";
-import { NavLink, NavLinkProps } from "react-router-dom";
+import { NavLink, NavLinkProps, To } from "react-router-dom";
 import classNames from "classnames";
 
 type Props = {
-  to: string;
+  to?: To;
   children: React.ReactNode;
   disabled?: boolean;
   className?: string;
-} & NavLinkProps;
+} & Omit<NavLinkProps, "to">;
 
-function getURL(to: string): URL {
+function getURL(to: To): URL {
+  if (typeof to !== "string") {
+    return getURL(to.pathname ?? "");
+  }
   try {
-    return new URL(to);
+    return new URL(to as string);
   } catch {
     let outurl = `${window.location.origin}${
       to.startsWith("/") ? to : "/" + to
@@ -29,7 +32,7 @@ export default function Link({
   ...props
 }: Props) {
   const link =
-    getURL(to).hostname === window.location.hostname ? (
+    to && getURL(to).hostname === window.location.hostname ? (
       <NavLink
         to={getURL(to).pathname}
         style={style}
@@ -39,7 +42,7 @@ export default function Link({
       </NavLink>
     ) : (
       <a
-        href={disabled ? undefined : getURL(to).origin}
+        href={disabled ? undefined : (to && getURL(to).origin) || undefined}
         style={
           typeof style === "function"
             ? style({