12345678910111213141516171819202122232425262728293031323334353637383940 |
- 'use client';
- import { default as NextLink } from 'next/link';
- import { usePathname } from 'next/navigation';
- import clsx from 'clsx';
- export default function Link({
- href,
- children,
- className,
- prefetch = false,
- exact = false,
- onClick = () => {},
- ...props
- }: {
- href: string
- children?: React.ReactNode
- prefetch?: boolean
- className?: string
- exact?: boolean
- onClick?: (event: React.MouseEvent) => void
- }): JSX.Element {
- const pathname = usePathname();
- return (
- <NextLink
- href={href}
- className={clsx(className, [
- (exact ? pathname === href : pathname.startsWith(href)) ? 'active' : '',
- ])}
- {...props}
- >
- {children}
- </NextLink>
- );
- }
|