UNPKG

create-vanjs

Version:

🍦 Quick tool for scaffolding your first VanJS project

18 lines (14 loc) 476 B
import { usePageContext } from "../renderer/usePageContext"; export { Link }; const Link = ({ href, children, ...props } = {}) => { const { urlPathname } = usePageContext(); const hrefAtt = () => href?.val ? href.val : href; const isActive = hrefAtt() === "/" ? urlPathname === hrefAtt() : urlPathname?.startsWith(hrefAtt()) || false; return ( <a href={hrefAtt} aria-current={isActive ? "page" : undefined} {...props}> {children} </a> ); };