Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Search a result in next page reactjs

I am having a search bar in my component. I want on click of search, it should call the search action and navigate the result to the parent component.

              onKeyPress={(event) => {
             if (event.key === "Enter") {


 onSearch(searchString) {
     // perform Search

I want it to navigate to a details page with the search String, in URL I am expecting something like: http://localhost:8080/details?search="searchString".

Can anyone help me with this?

like image 987
Singh Avatar asked Jan 25 '23 05:01


1 Answers

You could do this

onSearch(searchString) {
  // perform Search
  this.props.history.push("/details?search=" + encodeURIComponent(searchString));

Hope this helps.

like image 53
Daniele Ricci Avatar answered Jan 27 '23 20:01

Daniele Ricci