Skip to content

Instantly share code, notes, and snippets.

@dev-cyprium
Created February 22, 2021 22:12
Show Gist options
  • Save dev-cyprium/047773d802b77655c0063dad703cb60d to your computer and use it in GitHub Desktop.
Save dev-cyprium/047773d802b77655c0063dad703cb60d to your computer and use it in GitHub Desktop.
/*
router/index.js
*/
/* Rest of the router code */
const Link = ({ href, activeClass, children }) => {
const router = useRouter();
const navTo = (route) => (ev) => {
ev.preventDefault();
router.push(route);
};
return React.Children.map(children, (btn) =>
cloneElement(btn, {
className: `${btn.props.className} ${
router.route === href ? activeClass : ""
}`,
onClick: navTo(href)
})
);
};
// Don't forget to export this as well!
export { Link, ... };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment