Custom Menu

=====
var MenuLink = ({ label, to, activeOnlyWhenExact }) => {
    return (
        <Route path={to} exact={activeOnlyWhenExact} children={({match}) => {
            var active = match ? 'active' : '';
            return (
                <li className={active}>
                    <NavLink to={to} className="my-link">{label}</NavLink>
                </li>
            )
        }}></Route>
    )
};
=====
<MenuLink to="/" label="Trang chủ" activeOnlyWhenExact={true}></MenuLink>
=====
<Route path="/" exact component={Home}></Route>

Last updated

Was this helpful?