mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-28 16:49:36 +07:00
20 lines
506 B
TypeScript
20 lines
506 B
TypeScript
import { ComponentProps } from "react";
|
|
import { usePageContext } from "./context";
|
|
|
|
const Link = (props: ComponentProps<"a">) => {
|
|
const pageContext = usePageContext();
|
|
const { urlPathname } = pageContext;
|
|
const { href } = props;
|
|
|
|
const isActive =
|
|
href === "/" ? urlPathname === href : urlPathname.startsWith(href!);
|
|
|
|
const className = [props.className, isActive && "is-active"]
|
|
.filter(Boolean)
|
|
.join(" ");
|
|
|
|
return <a {...props} className={className} />;
|
|
};
|
|
|
|
export default Link;
|