0

I know this question a bit subjective, but still. Everytime a user types in new chars into input and runs a search I need to synchronize the new search state to the URL. So I can use either history.replaceState or history.search for that:

input.addEventListener('change', (event)=>{
   const searchString = event.current.value;
   history.replaceState(..., searchString);
});

or

input.addEventListener('change', (event)=>{
   const searchString = event.current.value;
   history.search = searchString;
});

history.search reloads the page though. Any other approach I'm missing? Maybe history.pushState is more applicable?

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • Maybe this? https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page – Mahatmasamatman Feb 21 '20 at 17:51
  • yeah, thanks, I considered `push` state, but I don't really want to add entries to history because it's not like a user is navigating anywhere – Max Koretskyi Feb 21 '20 at 17:55

0 Answers0