25706

Adding query parameters on form submission - React router 4

Question:

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?

Answer1:

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);

Recommend

  • Why does SelectList SelectedValue work on HttpGet but not on HttpPost?
  • Sending JSON Object from Javascript to Silverlight then triggering an event to update Silverlight
  • How to override the attr_protected?
  • Add delivery info to query in SAP Crystal Reports
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • Is mp4 stream able with ffserver?
  • Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory
  • Undefined navigator.push React-native 0.43.4
  • Prevent page break in text block with iText, XMLWorker
  • IE10 strips out hashtag from the URL
  • Python 3.2.2, error(scripts to exe)
  • NSIS decompiler
  • redirect_to root_url and return unless @user.activated
  • Django invalid literal for int() with base 10
  • Is playing sound in Javascript performance heavy?
  • Problem while Building a Setup Project for a windows Service?
  • How to attach a node.js readable stream to a Sendgrid email?
  • Insert into database using onclick function
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Updating server-side rendering client-side
  • Modifying destination and filename of gulp-svg-sprite
  • Knitr HTML Loop - Some HTML output, some R output
  • Trying to switch camera back to front but getting exception
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Symfony2: How to get request parameter
  • Hazelcast - OperationTimeoutException
  • How to pass list parameters for each object using Spring MVC?
  • RestKit - RKRequestDelegate does not exist
  • PHP: When would you need the self:: keyword?
  • Revoking OAuth Access Token Results in 404 Not Found
  • log4net write single file for each call to log.info
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • Getting error when using KSoap library to consume .NET web services
  • Angular 2 constructor injection vs direct access
  • sending mail using smtp is too slow
  • Programmatically clearing map cache
  • reshape alternating columns in less time and using less memory
  • How can I use threading to 'tick' a timer to be accessed by other threads?