N
N
Nikita Shchypylov2018-02-06 17:14:05
React
Nikita Shchypylov, 2018-02-06 17:14:05

Why activeNameClass in react-router only changes after page refresh?

This is what the sidebar looks like where clicks happen:

const sidebar = this.props.sidebar[0];
    const content = sidebar ? (
      Object.keys(sidebar).map(element => {
        const className = `icon ${sidebar[element].icon}`;
        const url = sidebar[element].url;
        return ( 
          <li key={element}>
            <NavLink to={url} activeClassName="active">
              <i className={className} />
              <span className="text">{sidebar[element].text}</span>
            </NavLink>
          </li>
        );
      })
    ) : (
      <div>Loading, please, waits</div>
    );

When I click, the routing happens. When I refresh the page, I get .activethe last clicked element. If I then click, nothing happens.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question