如何使材料UI 响应Button
组件起 react-router-dom 中的Link
组件的作用而不会丢失其原始内容样式?就像在点击时更改路线一样。
import Button from '@material-ui/core/Button';
<Button variant="contained" color="primary">
About Page
</Button>
对于这种情况,但要保持原始的Button
风格:
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>
答案 0 :(得分:5)
好吧,这很简单,我不知道为什么它对我不起作用:
只要这样做:
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>
答案 1 :(得分:1)
您需要将<Button />
包装在<Link />
组件内。
import Button from '@material-ui/core/Button';
import { Link } from 'react-router-dom';
const ButtonWithLink = () => (
<Link to="/about">
<Button variant="contained" color="primary">
About Page
</Button>
</Link>
)