added active link
This commit is contained in:
25
src/components/activeLink.tsx
Normal file
25
src/components/activeLink.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { useSelectedLayoutSegment } from 'next/navigation';
|
||||
|
||||
export const ActiveLink = ({
|
||||
href,
|
||||
className,
|
||||
activeClassName,
|
||||
children,
|
||||
}: {
|
||||
href: string;
|
||||
className: string;
|
||||
activeClassName: string;
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const segment = useSelectedLayoutSegment();
|
||||
const isActive = href.includes(segment);
|
||||
|
||||
return (
|
||||
<Link href={href} className={`${className}` + ' ' + (isActive ? `${activeClassName}` : '')}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user