如何在提交 redux-form 后重定向到主页?
how to redirect to home page after submitting redux-form?
我创建了一个 redux 表单,当点击提交按钮时它不会重定向到 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);
add.js
class AddNew extends Component{
handleSubmit = (values) => {
console.log('This Values',values)
}
render() {
return (
<div style={{ padding: 150 }}>
<Add onSubmit={this.handleSubmit}/>
</div>
)}
}
为了Redirect
,可以做的是在AddNew
组件的handleSubmit
函数中,可以用this.props.history.push()
[=17调用动态路由=]
现在假设您的 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);
我创建了一个 redux 表单,当点击提交按钮时它不会重定向到 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);
add.js
class AddNew extends Component{
handleSubmit = (values) => {
console.log('This Values',values)
}
render() {
return (
<div style={{ padding: 150 }}>
<Add onSubmit={this.handleSubmit}/>
</div>
)}
}
为了Redirect
,可以做的是在AddNew
组件的handleSubmit
函数中,可以用this.props.history.push()
[=17调用动态路由=]
现在假设您的 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);