Merge pull request 'Fixed props in link component' (#130) from fix/link-component into develop

Reviewed-on: http://85.143.176.51:3000/free-land/front-end/pulls/130
This commit is contained in:
Denis Gorbunov 2022-09-22 09:55:19 +00:00
commit 43a73bc538

View File

@ -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({