问题代码
interface CurProps {
}
interface dataInterface{
data?:any,
message:string|number,
code:number
}
interface resInterface{
data:dataInterface
}
class Login extends Component<CurProps, CurState>{
constructor(props:CurProps){
super(props);
}
//组件渲染完成后调用
componentDidMount=()=>{
this.props.history.push('/');
}
render(){
return (
<>1111</>
)
}
}
export default Login;
解决流程
1.把CurProps 继承RouteComponentProps
2.页面导出需要用withRouter()包裹
正确代码:
import {RouteComponentProps, withRouter} from "react-router-dom";
interface CurProps extends RouteComponentProps{
}
interface dataInterface{
data?:any,
message:string|number,
code:number
}
interface resInterface{
data:dataInterface
}
class Login extends Component<CurProps, CurState>{
constructor(props:CurProps){
super(props);
}
//组件渲染完成后调用
componentDidMount=()=>{
this.props.history.push('/');
}
render(){
return (
<>1111</>
)
}
}
export default withRouter(Login);
个人网站:https://www.php-china.com/
如有错误,请多多指教。
如对你有帮助,给个赞吧。