mirror of
https://github.com/cupcakearmy/fantus.git
synced 2026-04-02 17:35:22 +00:00
components
This commit is contained in:
20
components/link.tsx
Normal file
20
components/link.tsx
Normal 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
|
||||
Reference in New Issue
Block a user