CoastalCommitsPastes/client/components/Link.tsx

18 lines
491 B
TypeScript
Raw Normal View History

import type { LinkProps } from "@geist-ui/core"
import { Link as GeistLink } from "@geist-ui/core"
2022-04-09 20:48:19 -04:00
import { useRouter } from "next/router"
2022-03-06 20:20:01 -05:00
const Link = (props: LinkProps) => {
2022-04-09 20:48:19 -04:00
const { basePath } = useRouter()
const propHrefWithoutLeadingSlash =
props.href && props.href.startsWith("/")
? props.href.substring(1)
: props.href
const href = basePath
? `${basePath}/${propHrefWithoutLeadingSlash}`
: props.href
return <GeistLink {...props} href={href} />
2022-03-06 20:20:01 -05:00
}
2022-03-06 20:27:13 -05:00
export default Link