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

后端 未结 8 2038
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:31

    Example using react-router v4, redux-thunk and react-router-redux(5.0.0-alpha.6) package.

    When user uses search feature, I want him to be able to send url link for same query to a colleague.

    import { push } from 'react-router-redux';
    import qs from 'query-string';
    
    export const search = () => (dispatch) => {
        const query = { firstName: 'John', lastName: 'Doe' };
    
        //API call to retrieve records
        //...
    
        const searchString = qs.stringify(query);
    
        dispatch(push({
            search: searchString
        }))
    }
    
    0 讨论(0)
  • 2020-11-29 22:36

    It can also be written this way

    this.props.history.push(`${window.location.pathname}&page=${pageNumber}`)
    
    0 讨论(0)
提交回复
热议问题