我试图构建一个反应路由器组件,当该组件处于活动状态时会更新redux状态,但我还想为每个NavLink设置另一个活动的类名。不幸的是,isActive与activeClassName冲突,并且当我试图同时使用它们时,只有isActive属性有效。有什么办法可以同时使用它们吗?
class NavBar extends Component{
render(){
const {color} = this.props
const someFunc = () =>{
someFunction(xdxd)
}
const otherFunc = () =>{
someFunction(abcd)
}
return (
<nav id="menu" className=" d-flex flex-column position-fixed">
<ul id="Nav"className="mb-0 d-flex flex-column list-group">
<NavLink style={{color}} isActive={someFunc} activeClassName="my-bg-gray" className="menu-li mt-auto mr-0 mb-0 ml-auto rounded-circle" id="about_button" exact to="/"
>a</NavLink>
<NavLink style={{color}} isActive={someFunc} activeClassName="my-bg-gray" className="menu-li mt-auto mr-0 mb-0 ml-auto rounded-circle" id="projects_button" to="/projects"
>b</NavLink>
<NavLink style={{color}} isActive={someFunc} activeClassName="my-bg-green"className="menu-li mt-auto mr-0 mb-0 ml-auto rounded-circle" id="abilities_button" to="/abilities"
>c</NavLink>
<NavLink style={{color}} isActive={otherFunc} activeClassName="my-bg-green"className="menu-li mt-auto mr-0 mb-0 ml-auto rounded-circle" id="education_button" to="/education"
>d</NavLink>
<NavLink style={{color}} isActive={otherFunc} activeClassName="bg-white" className="menu-li mt-auto mr-0 mb-0 ml-auto rounded-circle" id="sendmessage_button" to="/sendmessage"
>e</NavLink>
<NavLink style={{color}} isActive={otherFunc} activeClassName="my-bg-green" className="menu-li mt-auto mr-0 mb-0 ml-auto rounded-circle" id="socials_button" to="/socials"
>f</NavLink>
</ul>
</nav>
);}}
const mapStateToProps = (state) => {
return { color: state.color };
};
export default connect(mapStateToProps,{})(NavBar);