Skip to content

No global handler for aborted navigation #3535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
e-cloud opened this issue Apr 28, 2021 · 2 comments
Closed

No global handler for aborted navigation #3535

e-cloud opened this issue Apr 28, 2021 · 2 comments

Comments

@e-cloud
Copy link

e-cloud commented Apr 28, 2021

What problem does this feature solve?

As a developer, I need to capture all navigation failure globally, not for one single navigation.

so, $router.push('xxx').catch(...) is not a solution.

For now, I have to hack to prototype to archive it.

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location: any) {
  return originalPush.bind(this)(location).catch((err) => {
    NProgress.done();
    return err;
  });
};

What does the proposed API look like?

VueRouter.prototype.onAbort = function() {
...
}

BTW, there was a similar issue, which was closed casually.
#3286

@wparad
Copy link

wparad commented Apr 28, 2021

As a developer, I need to capture all navigation failure globally, not for one single navigation.

But why?

I can see the value in never throwing an error, often the unnecessary .catch(() => {}) has to be added.

I wourd be more interested in never throwing, or logging an Vue message using the Vue global message handlers.

@posva
Copy link
Member

posva commented May 2, 2021

See #2881 (comment) on how to replicate the existing behavior on Vue Router 4. This can be added as it would be a breaking change

@posva posva closed this as completed May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants