redirect在react-router中找不到
来源:9-6 登陆功能实现
头发浓密去敲码
2022-03-19
报错图片如下,重新安装了react-router,还是没变
login组件的代码如下
import React, { PureComponent } from "react";
import { Redirect } from "react-router-dom";
import { connect } from "react-redux";
import {Input, LoginBox, LoginWrapper, Button} from "./style";
import {actionCreators} from './store';
class Login extends PureComponent {
render() {
const {login} = this.props;
if(!login){
return(
<LoginWrapper>
<LoginBox>
<Input placeholder="账号" ref={(input) => {this.account = input}}/>
<Input placeholder="密码" type='password' ref={(input) => {this.password = input}}/>
<Button onClick={() => this.props.login(this.account, this.password)}>登录</Button>
</LoginBox>
</LoginWrapper>
)
}else{
return <Redirect to='/' />
}
}
}
const mapState = (state) => ({
login: state.getIn(['login', 'login'])
});
const mapDispatch = (dispatch) => ({
login(accountElem, passwordElem){
dispatch(actionCreators.login(accountElem.value, passwordElem.value));
}
});
export default connect(mapState,mapDispatch)(Login);
非常感谢!
写回答
3回答
-
虞舟
2022-03-22
这个组件被废弃了,我用 <Navigate to="/"/> 也实现了
212022-11-14 -
头发浓密去敲码
提问者
2022-03-20
v6.2.2
00 -
Dell
2022-03-20
看下你的react-router-dom 的版本号
012022-03-20
相似问题