无法使用 Sagas 重定向到 React Redux 中的页面
Cannot Redirect to a page in React Redux with Sagas
当我想重定向 到'submit()' 函数末尾的“/欢迎”页面时,没有任何反应。这是提交功能:
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")
当异步函数解析时
当我想重定向 到'submit()' 函数末尾的“/欢迎”页面时,没有任何反应。这是提交功能:
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")
当异步函数解析时