Last active
July 6, 2024 21:07
-
-
Save vanessabrazuna/f2d73c885c27b49acbbea295935de803 to your computer and use it in GitHub Desktop.
react-router-dom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Link, LinkProps, useLocation } from 'react-router-dom' | |
export type NavLinkProps = LinkProps | |
export function NavLink(props: NavLinkProps) { | |
const { pathname } = useLocation() | |
return ( | |
<Link | |
data-current={pathname === props.to} | |
className="flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground data-[current=true]:text-foreground" | |
{...props} | |
/> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
useLocation - retorna a rota atual, pode ser usado como active
useNavigate - redirecionamento a partir de um click do botão, todas as vezes que não for um link.