CoastalCommitsPastes/client/components/link/index.tsx
Max Leiter 55c5ecfe6c
Update to next 13, switch to pnpm (#127)
* switch to pnpm

* dep improvements, style fixes, next/link codemod

* server: upgrade sqlite
2022-11-08 00:28:19 -08:00

26 lines
710 B
TypeScript

import { useRouter } from "next/router"
import NextLink from "next/link"
import styles from "./link.module.css"
type LinkProps = {
href: string,
colored?: boolean,
children: React.ReactNode
} & React.ComponentProps<typeof NextLink>
const Link = ({ href, colored, children, ...props }: LinkProps) => {
const { basePath } = useRouter()
const propHrefWithoutLeadingSlash =
href && href.startsWith("/") ? href.substring(1) : href
const url = basePath ? `${basePath}/${propHrefWithoutLeadingSlash}` : href
const className = colored ? `${styles.link} ${styles.color}` : styles.link
return (
<NextLink {...props} href={url} className={className}>
{children}
</NextLink>
)
}
export default Link