Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Link and NavLink react-router-dom components :hover not working #907

Open
austincondiff opened this issue Jun 21, 2017 · 9 comments
Open

Comments

@austincondiff
Copy link

austincondiff commented Jun 21, 2017

The hover does not work on react router components.

<li key="contactInfoPage" style={{display: 'inline-block'}}>
    <NavLink to="/contact-info" style={{
        display: 'inline-block',
        padding: '20px 16px 0 16px',
        textDecoration: 'none',
        color: '#36495a',
        textTransform: 'uppercase',
        fontSize: 12,
        fontWeight: 'bold',
        transition: '.2s',
        //the :hover below does not work
        ':hover': {
            color: '#0078d2'
        }
    }}>Contact Info</NavLink>
</li>

Sure I could simply style a span inside but where's the fun in that?

@mvbattan
Copy link

I'd close this since is duplicated: #398

@Nimelrian
Copy link

Nimelrian commented Sep 4, 2017

Definitely not fixed with the workaround when using React Router v4.2.2 and Radium v0.19.4.
Wrapping a Link or NavLink using the Radium HOC before using them does not cause the pseudo-selectors to work.

Minimal, Complete, and Verifiable Example:

import React from "react";
import { render } from "react-dom";
import { BrowserRouter, Link, NavLink } from "react-router-dom";
import Radium from "radium";

const RadiatingNavLink = Radium(NavLink);
const RadiatingLink = Radium(Link);

const App = () =>
  <BrowserRouter>
    <div>
      <div>
        <RadiatingNavLink
          to="/test1"
          style={{ background: "red", ":hover": { background: "green" } }}
          activeStyle={{ background: "cyan" }}
        >
          test1
        </RadiatingNavLink>
      </div>
      <div>
        <RadiatingNavLink
          to="/test2"
          style={{ background: "red", ":hover": { background: "green" } }}
          activeStyle={{ background: "cyan" }}
        >
          test2
        </RadiatingNavLink>
      </div>
      <div>
        <RadiatingNavLink
          to="/test3"
          style={{ background: "red", ":hover": { background: "green" } }}
          activeStyle={{ background: "cyan" }}
        >
          test3
        </RadiatingNavLink>
      </div>
      <div>
        <RadiatingLink
          to="/test3"
          style={{ background: "red", ":hover": { background: "green" } }}
        >
          LinkTest
        </RadiatingLink>
      </div>
    </div>
  </BrowserRouter>;

render(<App />, document.getElementById("root"));

@yonasstephen
Copy link

Yes, it is not working using React Router v4.2.0 and Radium v.0.19.5. Any other workaround?

@jakubrpawlowski
Copy link

jakubrpawlowski commented Feb 10, 2018

My temporary solution: remix-run/react-router#5496

@hardy1334
Copy link

@yonasstephen I'm also facing the similar problem,not working with React Router4.2.0

@martinpalmieri
Copy link

I use Glamor (https://github.com/threepointone/glamor) like this:

  const style = {
    MenuLink: {
      textDecoration: "none",
      color: "#000",
      ":hover": { color: "#8062ba" }
    }
  };
<NavLink to={item.path} {...css(style.MenuLink)} activeStyle={{ fontWeight: "600" }}>
  {item.name}
</NavLink>

@blu3printchris
Copy link

blu3printchris commented Jan 24, 2019

Any update on this? @Nimelrian answer works for me.

@douglasrcjames
Copy link

douglasrcjames commented Jan 21, 2021

Bumping this, an issue for me now and none of the workarounds above work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants