【发布时间】:2020-03-27 10:16:29
【问题描述】:
表单中的提交按钮应该执行其分配的功能并通过返回主页关闭组件,但是如果将按钮包裹在Link组件中,则该功能被取消。任何想法如何避免这种情况?
<Link to={{ pathname: "/"}} ><button type="submit" value="Submit">Save</button></Link>
handleEditFormSubmit = (index, e) => {
if (!this.canBeSubmitted()) {
e.preventDefault();
return alert("Please fill all empty text spaces");
}
e.preventDefault();
let products = [...this.state.products];
products.splice(index, 1, {name: this.state.name,
ean: this.state.ean,
type: this.state.type,
weight: this.state.weight,
color: this.state.color,
active: false})
this.setState({ products, name: "", ean: "", type: "", weight: "", color: "", active: false},
() => {
this.props.history.push("/");
}
);
}
【问题讨论】:
标签: reactjs react-router