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="/"/> 也实现了



2
1
hahaha225
感谢同学
2022-11-14
共1条回复

头发浓密去敲码

提问者

2022-03-20

v6.2.2

0
0

Dell

2022-03-20

看下你的react-router-dom 的版本号

0
1
头发浓密去敲码
v6.2.2
2022-03-20
共1条回复

React零基础入门到实战,完成企业级项目简书网站开发

主流新技术 React-redux,React-router4,贯穿基础语法

5275 学习 · 2496 问题

查看课程