mirror of
https://github.com/ArthurDanjou/arthurdanjou.fr.git
synced 2026-01-30 03:37:51 +01:00
Initial commit 🚀
This commit is contained in:
18
components/header/activelink/activelink.js
Normal file
18
components/header/activelink/activelink.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { withRouter } from 'next/router'
|
||||
import Link from 'next/link'
|
||||
import React, { Children } from 'react'
|
||||
|
||||
const ActiveLink = ({ router, children, ...props }) => {
|
||||
const child = Children.only(children)
|
||||
|
||||
let className = child.props.className || null
|
||||
if (router.pathname === props.href && props.activeClassName) {
|
||||
className = `${className !== null ? className : ''} ${props.activeClassName}`.trim()
|
||||
}
|
||||
|
||||
delete props.activeClassName
|
||||
|
||||
return <Link {...props}>{React.cloneElement(child, { className })}</Link>
|
||||
}
|
||||
|
||||
export default withRouter(ActiveLink)
|
||||
Reference in New Issue
Block a user