fix(useRouteQuery): differentiate undefined and null when writing value
#4382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting the PR, please make sure you do the following
fixes #123).Description
Both
vue-routeranduseRouteQuerydifferentiate betweenundefinedandnullfor query parameters when reading/getting the value:useRouteQueryhowever does not differentiate betweenundefinedandnullwhen writing/setting the value:In fact TypeScript even prevents us from assigning
undefinedto the value[1]in the default scenario.This PR adds
undefinedto the type definition and aligns the use ofundefinedandnullwithvue-routerwhen setting a value.I am not sure if this is considered a breaking change or not. Previouslly developers likely used
useRouteQuery('archived').value = null(because[1]prevented them from usingundefined) to "remove" the query parameter from the URL and this would now lead to an URL like/projects?archivedinstead of/projects. This is however aligned withvue-router.To remove the query param from the URL we would have to assign
undefinedor usenullas the default value (useRouteQuery('archived', null)) and then asignnull.I am not sure if this change in the URL could actually break something or "just" leads to uglier URLs which could be easily addressed with the two options mentioned above.
#3583 mentions these URL changes. The linked issue however (#3290) only complains about the default value not removing the query param, which still works with this PR.
If this change is considered breaking, we could only include it in the next major version. However I think this change is important to align
useRouteQuerywithvue-router.Additional context
These changes also allow us (with transform get/set) to have boolean flags in the URL while having a "pretty" URL like
/projects?archivedinstead of/projects?archived=or/projects?archived=1or similar.Also related