简体   繁体   中英

NavLink react-router-dom components :hover not working

The hover does not work on react router components. Image

JSX inline style attributes does not allow :hover . You need to put that in your stylesheet instead.

You can't and even shouldn't put pseudo-classes inline. Put css in class and then apply it by className like in example below:

JSX:

<NavLink to="/example" className="nav_link">Example</NavLink>

CSS

.nav {
  //other styles
  //...
  a.nav_link:hover {
  cursor: pointer;
  color: red; 
  }
}

Example

I prefer the CSS-in-JS method to set the class like so:

nav_link: {
  textDecoration: 'none',
  '&:hover': {
    textDecoration: 'none'
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM