Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react router how to prevent navlink from two classes

// :::ISSUE::: 
// class active is ALWAYS assigned to homepage which means TWO active elements
<NavLink to="/mywebpage" exact="true">
  homepage	
</NavLink>
<NavLink to="/mywebpage/contact">
  contact
</NavLink>

// :::SOLUTION:::
// Just add "/" in first line, at the end: to="/mywebpage" -> to="/mywebpage/"
// also remember to have exact="true" like in example above
 
PREVIOUS NEXT
Tagged: #react #router #prevent #navlink #classes
ADD COMMENT
Topic
Name
7+6 =