components

This commit is contained in:
cupcakearmy
2020-01-12 18:34:14 +01:00
parent e1e4c06d08
commit 94ac7b29aa
3 changed files with 195 additions and 0 deletions

20
components/link.tsx Normal file
View File

@@ -0,0 +1,20 @@
import React from 'react'
import NextLink, { LinkProps } from 'next/link'
import { useRouter } from 'next/router'
const Link: React.FC<LinkProps> = ({ href, children }) => {
const router = useRouter()
let className = ''
try {
// @ts-ignore
className = children.props.className || ''
} catch { }
if (router.pathname === href)
className = `${className} active`.trim()
return <NextLink href={href}>{React.cloneElement(children as React.ReactElement, { className })}</NextLink>
}
export default Link