react-router-dom#useMatch JavaScript Examples
The following examples show how to use
react-router-dom#useMatch.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppDrawer.js From module-federation-examples with MIT License | 6 votes |
function ListItemLink(props) {
const selected = useMatch(props.to);
const CustomLink = React.useMemo(
() => React.forwardRef((linkProps, ref) => <Link ref={ref} to={props.to} {...linkProps} />),
[props.to],
);
return (
<li>
<ListItem selected={selected} button component={CustomLink}>
<ListItemIcon>{props.icon}</ListItemIcon>
<ListItemText primary={props.text} />
</ListItem>
</li>
);
}
Example #2
Source File: Header.js From pro-organiser-application with MIT License | 6 votes |
function NavLink({ children, to, ...props }) {
let resolved = useResolvedPath(to);
let match = useMatch({ path: resolved.pathname, end: true });
return (
<div>
<Link
className={match ? styles.activeLink : styles.link}
to={to}
{...props}
>
{children}
</Link>
</div>
);
}