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

withQuery can't remove a query param from the path #66

Closed
BrandonlinU opened this issue Jul 21, 2022 · 0 comments · Fixed by #71
Closed

withQuery can't remove a query param from the path #66

BrandonlinU opened this issue Jul 21, 2022 · 0 comments · Fixed by #71

Comments

@BrandonlinU
Copy link
Contributor

Currently, we can't remove a query param from the original path using the query object given in withQuery without rebuild the entire URL.

Proposed solution

Based on the Vue Router behaviour, if you send a undefined value to a query parameter, it removes from the path; if you want to keep the param, but send it without value, then you can use a null value. This represent a breaking change, but it has the most sense for this scenario, because the undefined value should represent a value that does not exists, not "an empty value": for a empty value, we have the null value.

Current behaviour:

For param = undefined

const path = withQuery('https://example.com?page=2', { page: undefined });
console.log(path); // Return "https://example.com?page"

For param = null

const path = withQuery('https://example.com?page=2', { page: null });
console.log(path); // Return "https://example.com?page"

Proposed behaviour:

For param = undefined

const path = withQuery('https://example.com?page=2', { page: undefined });
console.log(path); // Return "https://example.com"

For param = null

const path = withQuery('https://example.com?page=2', { page: null });
console.log(path); // Return "https://example.com?page"
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

Successfully merging a pull request may close this issue.

1 participant