You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, a router instance has push and replace methods, and these two methods only support callback style, which they only accept callback as onComplete parameter and onAbort parameter. The push and replace methods themselves will return nothing.
I propose a new API which let push and replace methods return a Promise. This is just like how Vue.prototype.$nextTick behaves.
What does the proposed API look like?
For push and replace methods, if user provide a function as parameter and pass it to onComplete or onAbort parameter, just behave as same as current behavior.
However, if user doesn't provide those parameters, the push and replace should return a Promise like this:
router.push('/').then(/* just do something like in `onComplete` here */).catch(/* just do something like in `onAbort` here */)
This can let us use async/await:
try{awaitrouter.push('/')/* just do something like in `onComplete` here */}catch{/* just do something like in `onAbort` here */}
In the VueRouter's internal History instance, maybe the push method can be changed to:
What problem does this feature solve?
Currently, a router instance has
push
andreplace
methods, and these two methods only support callback style, which they only accept callback asonComplete
parameter andonAbort
parameter. Thepush
andreplace
methods themselves will return nothing.I propose a new API which let
push
andreplace
methods return aPromise
. This is just like howVue.prototype.$nextTick
behaves.What does the proposed API look like?
For
push
andreplace
methods, if user provide a function as parameter and pass it toonComplete
oronAbort
parameter, just behave as same as current behavior.However, if user doesn't provide those parameters, the
push
andreplace
should return aPromise
like this:This can let us use
async/await
:In the VueRouter's internal
History
instance, maybe thepush
method can be changed to:The text was updated successfully, but these errors were encountered: