How to use activeClassName to change the class of the upper layer or other tags in the jsx of react?

clipboard.png
1 li tag class can display the style normally using active, but it is not effective to replace the li tag with NavLink.
directly setting the style in NavLink (in the form of figure 2) can only change the class of the a tag (converted to a tag after html) rather than the li tag, so the effect can not be achieved.

I want to change the className in the li tag to active based on the route such as to= "/" address. How can we do that? Css is really a little complicated, directly to change css do not know how to change, is there a method that can be realized in react, or ideas that can be done?
Thank you very much, bosses.


className={{active: this.props.history.location.href === '/'}}

className= {this.props.history.location.pathname ='/'? 'active':''}

you can do this using ternary expressions in jsx.
you must first inject router information into the current component, otherwise there is no location.

import { withRouter } from 'react-router-dom'

export default withRouter()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e45bae-44b6f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e45bae-44b6f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?