I have this code:
constructor(props) {
super(props);
this.state = {
setMenu: (window.location.pathname.split("/")[1] == '') ? '/' : window.location.pathname.split("/")[1]
};
this.menuItens = new Menu();
this.menuItens = this.menuItens.Itens;
};
and in my sidebar menu item:
<NavLink tag={Link}
to={item.path}
title={item.title}
onClick={this.setMenu}
className={(this.state.setarMenu === item.title) ? 'active' : ''}>
<span>{item.nome}</span>
</NavLink>
I'm trying to change the state by calling a function:
setMenu = (event) => {
this.setState({setarMenu: event.target.title});
};
But unfortunately, sometimes the state doesn't change because the window.location.pathname came empty.
Anybody have a clue why this happens?
Solved, simply remove the tag of the NavLink component of Reactstrap and it works fine.
Appears that, with the span tag inside the NavLink, the component sometimes return only with no attributes like title={item.title} instead of with attributes that I need to "set menu" (setState).
BTW: In PT-BR we write "item" no "iten", that's why sometimes we "misspelled" it.
Thank you guys anyway.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments