[当我要重定向时到'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"/>
}
}
如果您需要有关我的项目的其他信息,请随时发表评论!有什么建议吗?
使用React Router的withRouter
HoC如下向组件提供{ match, history, location }
;
import { withRouter } from "react-router";
...
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(LoginPage));
使用history
,您可以在异步功能解决时执行history.push("/welcome")