Reactjs react路由器v4添加查询参数
我正在为react应用程序使用react路由器v4 在表单中,我想在onSubmit操作上添加查询参数 我的代码如下所示:Reactjs react路由器v4添加查询参数,reactjs,react-router,Reactjs,React Router,我正在为react应用程序使用react路由器v4 在表单中,我想在onSubmit操作上添加查询参数 我的代码如下所示: class FiltroCuentasCorrientes extends Component { ...//Other stuff. onSubmit(e) { e.preventDefault(); const { someVariable, otherVariable } = this.state; //Here I should add th
class FiltroCuentasCorrientes extends Component {
...//Other stuff.
onSubmit(e) {
e.preventDefault();
const { someVariable, otherVariable } = this.state;
//Here I should add the variables to the query param.
}
render() {
<Form onSubmit={(e) => this.onSubmit(e)}>
...
</Form>
}
}
类filterocurentascorrientes扩展组件{
……其他的东西。
提交(e){
e、 预防默认值();
const{someVariable,otherVariable}=this.state;
//在这里,我应该将变量添加到查询参数中。
}
render(){
此.onSubmit(e)}>
...
}
}
我不知道推荐的方法是什么
我是否应该在本地状态中设置一个变量,如shouldAddParam
,并使用我的参数呈现一个
或者使用路由器
上下文和导航到
方法
如何才能做到这一点?如果可能的话,我会在
render()
过程中尝试组合form
元素的action
属性。这样就没有必要防止违约
然而,如果您想使用React路由器“以编程方式重定向”,那么是的,您应该使用
this.context.router.push(path)
。。。正如您在中所看到的。如果可能的话,我会在
render()
期间尝试组合表单
元素的操作
属性。这样就没有必要防止违约
然而,如果您想使用React路由器“以编程方式重定向”,那么是的,您应该使用
this.context.router.push(path)
。。。正如你在书中看到的