Reputation: 809
I want to add for activeClassName in NavLink.
<NavLink exact to="/" activeClassName="main-category-item-active"> .... </NavLink>
<NavLink to="/?tab=1" activeClassName="main-category-item-active"> .... </NavLink>
<NavLink to="/?tab=2" activeClassName="main-category-item-active"> .... </NavLink>
But the result looks like this picture.
I think it's because the path is a query.
How Can I do?
Upvotes: 0
Views: 1018
Reputation: 13682
There is no support for processing query strings React router v4 and up.
Alternatively, you can use a simple wrapper component and use isActive to determine the activeness-logic.
// simple wrapper component for NavLink
const PathNavLink = (props) => (
<NavLink isActive={(_, { pathname }) => pathname == props.to} {...props} />
);
// usage
<PathNavLink exact to="/" activeClassName="main-category-item-active"> .... </PathNavLink>
Upvotes: 1