2

I am using react-router-dom props.history.replace to replace query string in URL (works as expected).

When I navigate to another URL using Link component and hit back, URL doesn't reflect previous push state (set using props.history.replace).

For example: we're at /privacy-guides and search for keyword veracrypt.

Following logic is executed:

props.history.replace({
  pathname: "/privacy-guides",
  search: queryString.stringify({
    search: value,
  }),
})

We're now at /privacy-guides?search=veracrypt.

We click on <Link to="/privacy-guides/how-to-backup-and-encrypt-data-using-rsync-and-veracrypt-on-macos">.

We're now at /privacy-guides/how-to-backup-and-encrypt-data-using-rsync-and-veracrypt-on-macos and click back button.

We're now at /privacy-guides vs expected /privacy-guides?search=veracrypt.

Why?

sunknudsen
  • 6,356
  • 3
  • 39
  • 76
  • Related: https://stackoverflow.com/questions/43613140/how-to-preserve-query-parameters-in-react-router-v4 – Anurag Srivastava Apr 07 '21 at 17:23
  • why not ```props.history.push(`/privacy-guides?search=${value}`)``` – Dastan Apr 07 '21 at 17:25
  • @Pengin I also tried that... and it doesn't work either... plus I like the idea of replacing current state vs adding state each times search changes (on keystrokes pause keystrokes for example). – sunknudsen Apr 07 '21 at 17:26

0 Answers0