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
Reset search with question mark value to the empty string #701
Comments
I have an alternative parsePath implementation (based on Regex) lying around, which coincedentially has the desired behavior: function parsePath(path) {
const parts = path.match(/(\/?[^?#]*)(\?[^#?]+)?(\#[^#?]+)?/);
if (parts && parts.length === 4) {
return {
pathname: parts[1] || "/",
search: parts[2] || "",
hash: parts[3] || ""
};
}
return {
pathname: "/",
search: "",
hash: ""
};
} I'll submit a PR later. |
Thank you for the excellent repro, @vadikace. I think I'd consider this a bug. Essentially what it boils down to is you've got 2 links: <Link to="/?">one</Link>
<Link to={{ pathname: '/', search: '?' }}>two</Link> In both cases those links take you to I'd be happy to accept a PR that fixes this. |
I'll get my hands on it soonish |
Hi, I would like to suggest a feature here. Currently I'm using react-router-dom for one of my projects, which of course uses history dependency under the hood. Both
push
andreplace
methods have two possible overloads and may be executed whether with path as string or location descriptor as object. Using push method with path works as expected and suppresses difference between f.e./about
and/about?
, whereas push called with location descriptor differentiate search values such as""
(empty string) and?
which causes redundant update issues in environment where you f.e. execute data fetching on search change, so thatlocation.search
equals to?
after such navigate action. Wouldn't it be applicable to reset next search from?
to""
--even if?
was explicitly set-- directly in history library to prevent such a case?For more detailed example you might have a look on this example with react-router-dom. Just click the navigations links and observe how fetch counter is increased.
The text was updated successfully, but these errors were encountered: