How to set activeClassName for wrapper element of Link or IndexLink in react-router?
Date : March 29 2020, 07:55 AM
|
React router - activeClassName on Link home
Date : March 29 2020, 07:55 AM
around this issue Since you have used to render home component. You should use IndexLink to provide link for Home page <li><IndexLink to="/" activeClassName="active">Home</IndexLink></li>
|
React-router activeClassName not working as expected
Date : March 29 2020, 07:55 AM
may help you . OK, seem to have resolved it - not sure if this is a proper solution or just a workaround, but it seems to have done the trick. The answer lies in the component. By giving it a prop of path and linking this to the changing URL, it rerenders the component each time the URL changes. Also by removing as suggested by oklas and changing it to , it prevents the active class from sticking on the link.<div className={styles.container}>
<SideMenu path={this.props.children.props.route.path} /> { //This 'path' property solves the problem by rerendering the SideMenu component every time the path changes }
<ViewPort>
{this.props.children}
</ViewPort>
</div>
|
React router v4 - activeStyle and activeClassName not working
Date : March 29 2020, 07:55 AM
With these it helps For some reason, my activeStyle and activeClassName props for NavLink component are not working. Am I doing something wrong here? Maybe I am using v3 syntax? , I believe the only problem is missing slashes, meaning: <NavLink activeStyle={{ color:'red' }} to="/archives"> Archives </NavLink>
<NavLink activeClassName="active" to="/settings"> Settings </NavLink>
|
React Router - NavLink activeStyle or activeClassName not working for nested routes
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm using react-router-dom. In my code, NavLink fails to apply activeStyle or activeClassName not even on page load/reload. I've nested routes but not using redux. , Try putting a slash before the to property. Changing hello.js to: render() {
return (
<div>
<h5>
<NavLink
to="/child-a"
activeStyle={{ color:'red' }}
exact
>child-a</NavLink>
</h5>
<h5>
<NavLink
to="/child-b"
activeStyle={{ color:'red' }}
exact
>child-b</NavLink>
</h5>
<div>
<div><h2>Hello</h2></div>
{this.props.children}
</div>
</div>
);
}
|