react-router-dom#NavLinkProps TypeScript Examples
The following examples show how to use
react-router-dom#NavLinkProps.
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: LinkItem.tsx From mayoor with MIT License | 6 votes |
MenuLinkItem = styled(NavLink)<NavLinkProps<unknown>>`
width: 100%;
display: flex;
align-items: center;
color: inherit;
text-decoration: none;
padding: 12px 24px;
margin: 2px 0;
font-weight: 600;
border-right: solid transparent 5px;
transition: all 0.2s;
color: ${Colors.DARK_GRAY3};
&.active {
background: ${Colors.LIGHT_GRAY4};
border-color: ${Colors.BLUE4};
}
&:hover {
background: ${Colors.LIGHT_GRAY4};
color: inherit;
text-decoration: none;
}
.anticon {
margin-right: 10px;
}
`
Example #2
Source File: Items.tsx From backstage with Apache License 2.0 | 5 votes |
WorkaroundNavLink = React.forwardRef<
HTMLAnchorElement,
NavLinkProps
>(function WorkaroundNavLinkWithRef(
{
to,
end,
style,
className,
activeStyle,
caseSensitive,
activeClassName = 'active',
'aria-current': ariaCurrentProp = 'page',
...rest
},
ref,
) {
let { pathname: locationPathname } = useLocation();
let { pathname: toPathname } = useResolvedPath(to);
if (!caseSensitive) {
locationPathname = locationPathname.toLocaleLowerCase('en-US');
toPathname = toPathname.toLocaleLowerCase('en-US');
}
let isActive = locationPathname === toPathname;
if (!isActive && !end) {
// This is the behavior that is different from the original NavLink
isActive = locationPathname.startsWith(`${toPathname}/`);
}
const ariaCurrent = isActive ? ariaCurrentProp : undefined;
return (
<Link
{...rest}
to={to}
ref={ref}
aria-current={ariaCurrent}
style={{ ...style, ...(isActive ? activeStyle : undefined) }}
className={classnames([
className,
isActive ? activeClassName : undefined,
])}
/>
);
})