fantus/components/link.tsx

20 lines
548 B
TypeScript
Raw Permalink Normal View History

2020-01-12 18:34:14 +01:00
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