使用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-line
class Login extends React.Component<HomeProps,IState> {
constructor(props: HomeProps) {
super(props);
}
public jump = () => {
console.log('跳转');
this.props.history.push('/index');
}
render() {
return (
<div>login</div>
)
}
}