Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use button as link in material-ui react with out underline and change color text?

I just made a page, and use link wrapped button, but problem is when i do that, button text have underline

Like this(log out)

so my question is, how to make a button router in react and not change anything in button, just add action with button, click it, and it done, i also do it with function but it show error like this

weird is when i run on sandbox it not have that error https://codesandbox.io/s/quizzical-gould-olgow

here my code in local

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import './studentHome.css'
import ExitToAppIcon from '@material-ui/icons/ExitToApp';
import { withRouter, Link } from "react-router-dom";

const styles = {
  root: {
    flexGrow: 1,
  },
  flex: {
    flex: 1,
  },
  menuButton: {
    marginLeft: -12,
    marginRight: 20,
  },
};
const logout=()=>{
    this.props.history.push("/home");
}
function ButtonAppBar(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <AppBar position="static">
        <Toolbar>
          <IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
            <MenuIcon />
          </IconButton>
          <Typography variant="title" color="inherit" className={classes.flex}>
            Hệ thống thi ABC-ONLINE
          </Typography>
          <ExitToAppIcon/>
          <Link to="/"></Link>
          <Button color="inherit" onClick>Log Out</Button>

        </Toolbar>
      </AppBar>
    </div>
  );
}

ButtonAppBar.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ButtonAppBar);

in my local, i copy the same code as codesandbox and it show error, i don't know why, but use link, it have underline text,please help, thanks

like image 632
Thi Ôn Avatar asked Nov 17 '25 13:11

Thi Ôn


1 Answers

The react-router-dom Link (LinkAnchor) uses an <a> Tag, which has underline per default.

It should work if you add textdecoration: none to the <Link> Tag:

<Link to="/" style="text-decoration: none">
    <Button color="inherit" onClick>Log Out</Button>
</Link>

(Note that Browsers might behave differently, but this solution should work for all, to my knowledge)

like image 200
kca Avatar answered Nov 20 '25 03:11

kca