How to get rid of underline for Link component of React Router? How to get rid of underline for Link component of React Router? javascript javascript

How to get rid of underline for Link component of React Router?


I see you're using inline styles. textDecoration: 'none' is used in child, where in fact it should be used inside <Link> as such:

<Link to="first" style={{ textDecoration: 'none' }}>  <MenuItem style={{ paddingLeft: 13 }}>Team 1</MenuItem></Link>

<Link> will essentially return a standard <a> tag, which is why we apply textDecoration rule there.

I hope that helps


I think the best way to use react-router-dom Link in a MenuItem (and other MaterialUI component such as buttons) is to pass the Link in the "component" prop

<Menu>   <MenuItem component={Link} to={'/first'}>Team 1</MenuItem>   <MenuItem component={Link} to={'/second'}>Team 2</MenuItem></Menu>

you need to pass the route path in the 'to' prop of the "MenuItem" (which will be passed down to the Link component). In this way you don't need to add any style as it will use the MenuItem style


If you are using styled-components, you could do something like this:

import React, { Component } from 'react';import { Link } from 'react-router-dom';import styled from 'styled-components';const StyledLink = styled(Link)`    text-decoration: none;    &:focus, &:hover, &:visited, &:link, &:active {        text-decoration: none;    }`;export default (props) => <StyledLink {...props} />;