Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...