3

Same question as here, but for react-router version 4.

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

This will probably be closed because I don't have any code to show, but at github they say "ask on Stack Overflow", and it's not in the documentation as far as I can see.

1

1 Answer 1

6

You can use the withRouter higher order component to access the history directly.

e.g.

import React, { Component } from 'react
import { withRouter } from 'react-router'

class MyComp extends Component {
  doStuff = () => {
    this.props.history.push({
      pathname: '/pathname',
      search: '?stuff=done'
    })
  }

  render () {
    <button onClick={this.doStuff}>Do stuff</button>
  }
}

export default withRouter(MyComp)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.