本文介绍了如何使Material UI的React Button充当react-router-dom链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使材料UI 响应Button组件充当 react-router-dom 中的Link组件,同时又不丢失其原始样式?就像在点击时更改路线一样.

How can I make a Material UI react Button component act as a Link component from react-router-dom without losing it's original style? Like changing the route on click.

import Button from '@material-ui/core/Button';

<Button variant="contained" color="primary">
    About Page
</Button>

对于这样的事情,但保持原始的Button样式:

To something like this, but maintaining the original Button style:

import Button from '@material-ui/core/Button';
import { Link } from 'react-router-dom';

<Button variant="contained" color="primary">
    <Link to="/about">
        About Page
    </Link>
</Button>

推荐答案

好吧,这很简单,我不知道为什么它不能与我一起工作:

Okay, this is very easy, I don't know why it was not working with me:

只要这样做:

import Button from '@material-ui/core/Button';
import { Link } from 'react-router-dom';

<Button component={ Link } to="/about" variant="contained" color="primary">
    About Page
</Button>

这篇关于如何使Material UI的React Button充当react-router-dom链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 08:36