Skip to content

Commit

Permalink
update <Link
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomsik committed Apr 16, 2024
1 parent aeb4a36 commit 07cf1cd
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/app/_components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ export const Link = props => {
* A wrapper around the Link component that adds an active class to the
* link when the route is active.
**/
export const NavLink = ({ href, activeClass = "active", exact = false, ...props }) => {
export const NavLink = ({ href, class: className = "", activeClass = "active", exact = false, ...props }) => {
// Touch the currentRoute to subscribe to changes
router.currentRoute

if (router.match(exact ? href : `${href}*`)) {
props.class = (props.class ?? props.className ?? "") + " " + activeClass
}
const active = router.match(exact ? href : `${href}*`)

return <Link href={href} {...props} />
return <Link class={`${className} ${active ? activeClass : ""}`} href={href} {...props} />
}

0 comments on commit 07cf1cd

Please sign in to comment.