How do you programmatically update query params in react-router?

后端 未结 8 2049
Happy的楠姐
Happy的楠姐 2020-11-29 21:41

I can\'t seem to find how to update query params with react-router without using . hashHistory.push(url) doesn\'t seem to register que

8条回答
  •  心在旅途
    2020-11-29 22:23

    John's answer is correct. When I'm dealing with params I also need URLSearchParams interface:

    this.props.history.push({
        pathname: '/client',
        search: "?" + new URLSearchParams({clientId: clientId}).toString()
    })
    

    You might also need to wrap your component with a withRouter HOC eg. export default withRouter(YourComponent);.

提交回复
热议问题