Skip to content
Discussion options

You must be logged in to vote

I would avoid carrying next through 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:

  1. The argument order is beforeRouteLeave(to, from), not from, to. If your code is checking the route being left, that is from.name; if you meant the destination route, use to.name.
  2. beforeRouteLeave already has access to this, and in Vue Router 4 it can return a value or a Promise. So the modal can resolve the navigation instead of storing/calling next.

The shape I would use is:

beforeRouteLeave(to, from) {
  if (
    (from.name === "Test1" || from.name === "Test2") &&
    

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@steven-twerdochlib
Comment options

@yudin-s
Comment options

Answer selected by steven-twerdochlib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants