How to set activeClassName for wrapper element of Link or IndexLink in react-router?

前端 未结 10 1524
醉酒成梦
醉酒成梦 2020-12-07 15:56

I am new to the ReactJS world, and would like to know how can I pass active class name to the

  • element instead of (Link) element
  • 10条回答
    •  陌清茗
      陌清茗 (楼主)
      2020-12-07 16:34

      Using React Router v4, I only got it to work by including the

    • tags within the NavLink component. The solutions which have the
    • tags wrapping the links resulted in the HOME
    • tag always having the active class.

      import React from 'react'
      import { NavLink } from 'react-router-dom';
      
      class Header extends React.Component {
      
        render() {
          return (
            
      ) } } export default Header

      I adjusted the li and a CSS selectors accordingly.

    提交回复
    热议问题