Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History push/replace doesn't clear search and hash as expected #859

Open
adamkovalsky opened this issue Mar 4, 2021 · 4 comments
Open

Comments

@adamkovalsky
Copy link

Calling history.push or history.replace with a path that doesn't contain a search or a hash doesn't clear any existing search or hash from the location and carries them forward to the new location. This can be easily seen with the following simple test:

const history = createMemoryHistory({
    initialEntries: ["/one?foo=bar#abcdef"],
});
history.push("/test");
expect(history.location).toMatchObject({
    pathname: "/test",
    search: "",
    hash: "",
    state: null,
    key: expect.any(String),
});

The only way to circumvent this is to explicitly pass a PartialPath object with empty search and hash properties:

history.push({pathname: "/test", search: "", hash: ""});

This happens due to the way getNextLocation appends the specified to location to the current location:

https://github.com/ReactTraining/history/blob/28c89f4091ae9e1b0001341ea60c629674e83627/packages/history/index.ts#L479-L486

This is a regression in v5 that didn't occur with v4.

@StringEpsilon
Copy link

Duplicate of #814 / #808?

@adamkovalsky
Copy link
Author

Duplicate of #814 / #808?

Looks like it is, but I'll leave it up here anyway in case someone pays attention.

@rzyanhao
Copy link

same problem

@StanislavVoronov
Copy link

Any plans to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants