0

The desired effect when submitting a form using React router 4 is to append the search query to the end of the URL.

My current setup will send an API request on form submission, and then render the results in the render method.

Without using Links or Redirects, is there a way to add the query onto the URL, maybe from within the form submission method?

Morleee
  • 349
  • 2
  • 8
  • 1
    You could use the `history` object in your submission function. Check out if this previous question to see if it's what you're looking for: http://stackoverflow.com/questions/42672842/how-to-get-history-on-react-router-v4 – shotor May 22 '17 at 09:12

1 Answers1

1

You can dynamically push the queries to the url like

this.props.router.push({
  pathname: '/yourRoute',
  query: { someQuery: 'value' }
})

Connect your Component with witRouter to be able to use the router prop

import { withRouter } from 'react-router'

....


export default withRouter(App);
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400