Skip to content

Instantly share code, notes, and snippets.

@vanessabrazuna
Last active July 6, 2024 21:07
Show Gist options
  • Save vanessabrazuna/f2d73c885c27b49acbbea295935de803 to your computer and use it in GitHub Desktop.
Save vanessabrazuna/f2d73c885c27b49acbbea295935de803 to your computer and use it in GitHub Desktop.
react-router-dom
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}
/>
)
}
@vanessabrazuna
Copy link
Author

vanessabrazuna commented Jul 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment