本文共 710 字,大约阅读时间需要 2 分钟。
使用react路由器v4和Typescript以编程方式导航时出错:
Property 'history' does not exist on type 'Readonly & Readonly<{ children?: ReactNode; }>
解决方法:
你需要导入import { RouteComponentProps } from “react-router-dom”; RouteComponentProps接口有你正在寻找的道具。 例如:import { RouteComponentProps} from "react-router-dom";interface IProps { }type HomeProps = IProps & RouteComponentProps;interface IState { }// eslint-disable-next-lineclass Login extends React.Component{ constructor(props: HomeProps) { super(props); } public jump = () => { console.log('跳转'); this.props.history.push('/index'); } render() { return ( login) } }
转载地址:http://itkmf.baihongyu.com/