Skip to content

Add a way to catch a route cancel #2011

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
ghost opened this issue Jan 19, 2018 · 5 comments
Closed

Add a way to catch a route cancel #2011

ghost opened this issue Jan 19, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Jan 19, 2018

There are occasions where a route should be handled everytime it’s considered. For example, I’ve seen it suggested that VueRouter could be used to show a loading indicator by doing the following:

router.beforeEach((to, from, next) => {
    LoadIndicator.show();
    next();
});
router.afterEach((to, from) => {
    LoadIndicator.hide();
});

A route can be cancelled in a component’s beforeRouteEnter method with next(false), but AfterEach won’t fire since the route never actually loaded and the loading indicatior is stuck.

Something like that would be great:

router.cancel((to, from) => {
    LoadIndicator.hide();
});
@posva
Copy link
Member

posva commented Jan 19, 2018

Use router.onError in combination with next(err) (https://router.vuejs.org/en/api/router-instance.html#methods). It also allows you turn the bar red and similar things

@posva posva closed this as completed Jan 19, 2018
@JounQin
Copy link
Contributor

JounQin commented Jan 19, 2018

This also occurs on trying to go to another route but which redirects to itself.

@posva
Copy link
Member

posva commented Jan 19, 2018

@JounQin mhh, that may be different though. Let me give it a second look

@posva posva reopened this Jan 19, 2018
@ghost
Copy link
Author

ghost commented Jan 19, 2018

@JounQin wrote:

This also occurs on trying to go to another route but which redirects to itself

Second this... there's no way to catch redirect to itself

@posva
Copy link
Member

posva commented Jan 19, 2018

Closing in favour of #2012
if you have a use case about hooking on redirects, I'll like to hear it there 🙂

@posva posva closed this as completed Jan 19, 2018
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

2 participants