【发布时间】:2019-09-17 17:06:56
【问题描述】:
我正在尝试将类组件 React 应用程序迁移到带有钩子的功能组件。
在使用类组件时,我使用Link 组件将Button 组件传递给Button 组件,因为我使用的是react-router-dom 库。
但现在我正在尝试使用 Paratron/hookrouter 库进行路由,但在将 A 组件传递给 Button 时出现错误:
TypeError: props.href 未定义
我的代码现在看起来像这样:
import React, { Fragment } from 'react';
import { Grid, Button } from '@material-ui/core';
import { A } from 'hookrouter';
import './styles.css';
const Home = props => {
return (
<Fragment>
<Grid container spacing={24} className="landing">
<Grid item xs={6}>
<Button
variant="contained"
color="primary"
size="large"
component={A}
to="/login"
>Login</Button>
</Grid>
<Grid item xs={6}>
<Button
variant="contained"
color="secondary"
size="large"
component={A}
to="/contact"
>Contact us</Button>
</Grid>
</Grid>
</Fragment>
);
}
export default Home;
我猜这个A 组件不包含href 属性。不知道如何进行。任何 cmets 将不胜感激。
【问题讨论】:
标签: reactjs material-ui hookrouter