Repository navigation
How to remove next()? #2770
|
I see next() will be getting deprecated at some point in the near future so I want to get rid of it but I don't understand how.
|
Replies: 1 comment 2 replies
|
For this specific guard, you probably should not remove Vue Router 4 deprecated the general “call So your current shape is still the correct instance-based form: beforeRouteEnter(to, from, next) {
next((vm: any) => {
if (!vm.isRememberExpandedRoute(from.name)) {
vm.$store.commit("clearExpanded");
}
});
}If you really want to remove beforeRouteEnter(to, from) {
if (!isRememberExpandedRouteName(from.name)) {
store.commit("clearExpanded");
}
}But you cannot simply rewrite this as: beforeRouteEnter(to, from) {
this.isRememberExpandedRoute(...)
}because So the decision rule is: keep If this clarifies the migration path, please mark it as answered so others know that |
I would avoid carrying
nextthrough the event bus here. In Vue Router 4, the leave guard can wait for your modal directly, so the event bus only needs to open the modal and later resolve the guard.Two details matter here:
beforeRouteLeave(to, from), notfrom, to. If your code is checking the route being left, that isfrom.name; if you meant the destination route, useto.name.beforeRouteLeavealready has access tothis, and in Vue Router 4 it can return a value or a Promise. So the modal can resolve the navigation instead of storing/callingnext.The shape I would use is: