mirror of
https://github.com/cupcakearmy/fantus.git
synced 2024-11-01 13:04:34 +01:00
20 lines
548 B
TypeScript
20 lines
548 B
TypeScript
|
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
|