Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

18 wiersze
562 B

  1. import { withRouter } from 'next/router';
  2. import Link from 'next/link';
  3. import React, { Children } from 'react';
  4. const ActiveLink = ({ router, children, ...props }) => {
  5. const child = Children.only(children);
  6. let className = child.props.className || '';
  7. if (router.pathname === props.href && props.activeClassName) {
  8. className = `${className} ${props.activeClassName}`.trim();
  9. }
  10. delete props.activeClassName;
  11. return <Link {...props}>{React.cloneElement(child, { className })}</Link>;
  12. };
  13. export default withRouter(ActiveLink);