Created
February 22, 2021 22:12
-
-
Save dev-cyprium/047773d802b77655c0063dad703cb60d to your computer and use it in GitHub Desktop.
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
/* | |
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