2

React router V4.2 does not get the visited style

const activeLink = {
   "color": "red"
} 
<Link to="/" activeStyle={activeLink}>
  All categories
</Link>

I have tried with to, but no success

Tholle
  • 108,070
  • 19
  • 198
  • 189
Yaks10
  • 483
  • 9
  • 20
  • You can refer this https://stackoverflow.com/questions/47693540/get-an-active-route-with-react-router-in-reactjs/47766816#47766816 – Shubham Khatri Jul 26 '18 at 10:04

3 Answers3

2

The Link component doesn't have activeStyle, but the NavLink component does.

<NavLink
  exact
  to="/"
  activeStyle={{ color: "red" }}
>
  All categories
</NavLink>
Tholle
  • 108,070
  • 19
  • 198
  • 189
1

Seems that Link doesn't support this property.

You may want to try NavLink:

React Router Documentation: A special version of the that will add styling attributes to the rendered element when it matches the current URL

For more info: https://reacttraining.com/react-router/web/api/NavLink

Ponpon32
  • 2,150
  • 2
  • 15
  • 26
0

Problem solved, tnx 1. it must be but not 2. exect={true} is mandatory

Yaks10
  • 483
  • 9
  • 20