Eager way to update query parameters #2359
Unanswered
plehnen
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What problem is this solving
I am having a hard time to describe the problem I am facing, but I try my best to make it clear.
The following is just one example. Over the past years I had this issue multiple times and had a hard time finding issue and work around it.
Imagine two composables (usePagination and useQueryFilters). Both update the query parameters of the current page. i.e.:
There are situations where both do this at the same "tick". Component A is adding "paramA", Component B is adding "paramB". And while B tries to keep everything via
...route.query
, data gets lost. Thats becauseroute.query
is not yet updated, as therouter.replace
is async.Since I am in a complete different component/composable, I cannot await the other router.replace and therefore don't know that my router.replace is basically undoing the other composables changes to the query.
Proposed solution
I wish I could update the query parameters in an eager way.
If somewhere a router.push is being called I want to have access to the resulting route immediately.
Maybe something like
const route = useResolvedRoute()
which is already reflecting what the route will be after the nextTick.Describe alternatives you've considered
It doesn't help to make an
await nextTick()
in the "second" composable, as I would have to perform twoawait nextTick()
in the third one, and it still can happen that the execution happens in the same render cycle.My current work-around is a "useQueryManager" composable which stores my changes internally and gives me an API to just update the query parameters and takes care of the syncing. It's really ugly and complicated, but works. Still, I would love to have a way to do this with vue-router nativly.
Beta Was this translation helpful? Give feedback.
All reactions