无法使用Sagas重定向到React Redux中的页面

问题描述 投票:0回答:1

[当我要重定向时到'submit()'函数末尾的'/ welcome'页面。这是提交功能:

function submit ({ firstName, lastName, email }, submitAction) {

    let error = {}
    let isError = false

    if(firstName.trim() === '') {
        error.firstName = 'Required'
        isError = true
    }

    if(isError) {
        throw new SubmissionError(error)
    } else {
        //submit form to local storage
        console.log('before calling submit')
        submitAction({firstName, lastName, email})
        //Redirect to another page  
        return <Redirect to="/welcome"/>    
    }
}

如果您需要有关我的项目的其他信息,请随时发表评论!有什么建议吗?

reactjs web redux react-router redux-saga
1个回答
0
投票

使用React Router的withRouter HoC如下向组件提供{ match, history, location }

import { withRouter } from "react-router";

...

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(LoginPage));

使用history,您可以在异步功能解决时执行history.push("/welcome")

© www.soinside.com 2019 - 2024. All rights reserved.