Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 提交redux表单后如何重定向到主页?_Reactjs_Redux Form - Fatal编程技术网

Reactjs 提交redux表单后如何重定向到主页?

Reactjs 提交redux表单后如何重定向到主页?,reactjs,redux-form,Reactjs,Redux Form,我已经创建了一个redux表单,当单击submit按钮时,它不会重定向到app.js页面,url将更改为此http://localhost:3000/?name=Cook&phone=45625465265&email=cook%40yahoo&work=Engineer&city= 这是我写的- form.js const Form=({handleSubmit})=>( <form onSubmit={handleSubmit}> <center>

我已经创建了一个redux表单,当单击submit按钮时,它不会重定向到app.js页面,url将更改为此
http://localhost:3000/?name=Cook&phone=45625465265&email=cook%40yahoo&work=Engineer&city=

这是我写的-

form.js

const Form=({handleSubmit})=>(
  <form onSubmit={handleSubmit}>
    <center>
    <div>
      <label>First Name</label>
      <Field type="text" component="input" placeholder="Name" name="name"/>
    </div>
    <div>
      <label>Address</label>
      <Field type="text" component="input" placeholder="Phone" name="phone" />
    </div>
    <button type="submit">Submit</button>
  </center>
  </form>
)


export default reduxForm({
  form: 'form',
  fields: ['name', 'address']
})(Form);
const Form=({handleSubmit})=>(
名字
地址
提交
)
导出默认reduxForm({
表格:'表格',
字段:[“名称”、“地址”]
})(表格);
add.js

class AddNew extends Component{
  handleSubmit = (values) => {
      console.log('This Values',values)
  }
  render() {


    return (
    <div style={{ padding: 150 }}>
      <Add onSubmit={this.handleSubmit}/>
    </div>
  )}
  }
class AddNew扩展组件{
handleSubmit=(值)=>{
console.log('This Values',Values)
}
render(){
返回(
)}
}

为了
重定向
,您可以做的是,在
AddNew
组件的
handleSubmit
函数中,您可以使用
this.props.history.push()调用动态路由

现在假设您的
App.js
在路径为
/App

您可以执行以下操作

import {withRouter} from 'react-router'

class AddNew extends Component{

  handleSubmit = (values) => {
      console.log('This Values',values)
      this.props.history.push('/app');
  }
  render() {


    return (
    <div style={{ padding: 150 }}>
      <Add onSubmit={this.handleSubmit}/>
    </div>
  )}
  }

export default withRouter(AddNew);
从“react router”导入{withRouter}
类AddNew扩展组件{
handleSubmit=(值)=>{
console.log('This Values',Values)
this.props.history.push('/app');
}
render(){
返回(
)}
}
使用路由器导出默认值(AddNew);

您能否显示代码,说明您是如何调用Redux表单的,以及您是如何尝试调用Redux表单的redirect@Shubham我已经更新了问题,非常感谢Shubham。您能告诉我如何在app中传递这些值,以及如何在app.js的控制台中打印这些值吗?我无法访问app.js上的props.formStates:(你能在你问的前一个问题中添加你的应用程序组件代码吗?)这种方法的问题是,如果你的请求因任何原因失败,你可能不想重定向…@Will,在这种情况下,当请求成功时,你会有条件地编写
this.props.history.push('/app');