2

I'm using combination of Semantic-UI-React and react-router-dom I have a Navigation Component with just 2 links.

They look like this (NavLink comes from react-router-dom):

 <Menu.Item name="home" as={NavLink} to="/" />
 <Menu.Item name="protected" as={NavLink} exact to="/protected" />

When I click on the Protected Link on my site, the component loads and I'm on the /protected route. But the only link that is active is the Home NavLink.

I tried it with different variants. For example I added activeClassName="active" to both of them. I tried it with exact for all 2 or just one route. Nothing changes.

I found a related question: With React Semantic UI use NavLink to set active page class?

I tried it exactly like this, but it won't work on my site.

What could be the issue?

1 Answer 1

3

Solved:

My Navbar component wasn't connected to the router. I connected it with the withRouter helper from react-router-dom

That fixed the problem. Code looks like this now:

<Menu.Item
  name="home"
  as={NavLink}
  exact
  to="/"
  activeClassName="active"
/>
<Menu.Item        
  name="protected"
  as={NavLink}
  to="/protected"
  activeClassName="active"
/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.