History: `push()` and `replace()` will keep current `search` and `hash` string

Created on 8 Jul 2020  路  6Comments  路  Source: ReactTraining/history

When
Current location is http://localhost?a=a#b

Do

history.push('/');
// OR
history.replace('/');

Expect
Location change to http://localhost

Actual
Location still is http://localhost?a=a#b

Most helpful comment

Got the same issue

All 6 comments

Got the same issue

Yeah, this definitely seems like a bug to me too as it's a breaking change that is not documented with the 5.0.0 release, and just feels very unintuitive.

https://github.com/ReactTraining/history/releases/tag/v5.0.0

I think what I am seeing the same issue, but with "createHashHistory":

  1. My URL is: http://localhost:8080/esp/files/index.html#/main?lastNDays=31&protected=false&state=completed
  2. The user hand edits the URL in the address bar to: http://localhost:8080/esp/files/index.html#/main?lastNDays=999&protected=true
  3. In history.listen I still get: ?lastNDays=31&protected=false&state=completed for the search...

Here's my workaround:

const push = (to, state) => history.push({
  hash: '',
  search: '',
  ...(typeof to === 'string' ? parsePath(to) : to)
}, state)

It looks more like a bug than a feature 馃

same is here #808

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andi5 picture andi5  路  6Comments

sidoruk-sv picture sidoruk-sv  路  3Comments

johnjesse picture johnjesse  路  6Comments

kirill-konshin picture kirill-konshin  路  7Comments

vchibilisco-convey picture vchibilisco-convey  路  3Comments