-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Add onComplete & onAbort to router-link #3027
Comments
Implemented by #3114. |
I completely forgot about this issue. This kind of thing should go through the thinking process of an RFC in our RFC repo at vuejs/rfcs. One of the things I see is using events instead of callbacks, which is more adapted to Vue. Another thing would be giving more specific examples about what is being done onAbort/onComplete that is specific to that router-link. To me this is the kind of thing that would go in an Right now this can be achieved with an event listener that calls |
@posva: Could you please clarify how the workaround would look like? Currently the best solution without this PR seems to be forking the |
We have one use case, which might be connected to this issue, but correct me if I'm wrong. const state = Vue.observable({ navigating: false });
router.beforeEach((to, from, next) {
state.navigating = true;
next();
});
router.afterEach(() => {
state.navigating = false;
}); By registering these guards before any other guards, I can make sure that loading indicator will be shown until all other global, in-component and router guards are resolved, async components are loaded, etc. router.onError(() => {
state.navigating = false;
}); That is good. However, if one of the guards will do |
@posva I can work on Pull Request to add router's |
This is not about a guard 😅 |
Is there any issue, ticket or rfc where progress for this feature can be tracked? I linked PR above, which seems related and can potentially solve this issue. |
@bponomarenko this issue is about adding two event handlers to router-link, it's still at a discussion state. I don't think it's worth adding because if you need to react to the navigation state, you will be better off using |
@posva As a user it feel odd to me that there is this limitation between what's available through I'm not familiar if that level of change requires an RFC or not, but I already know I wouldn't be able to commit to the time to write it. If someone else wants to take this on feel free. |
@posva You are right, this issue is about changes to Proposed changes in referred #3042 doesn't really solve a problem for us, as it is not possible to always use |
Also need global OnAbort router hook. |
Lol, i explained same thing one year ago... And today you said again that i should read docs, lol... |
These days one can do But nothing like that seems to exist for |
(My use case is that I want to focus a particular element on the new page after the user clicks on a particular link.) |
OK, it seems that in v4, |
What problem does this feature solve?
In 2.2.0 Vue added
onComplete
andonAbort
callbacks torouter.push
, however there seems to be no equivalvent when using<router-link>
. I've seen suggestions that can you usebeforeRouteEnter
as an alteranative in some cases, however I have a case where I have a<header>
containing<router-link>
s that remains on the page after a user clicks on the router link, I want to be able to change a property of the header after the user has clicked the link. SobeforeRouteEnter
would not work for my case. Ideally I'd like to be able to supplyonComplete
andonAbort
to therouter-link
directly.What does the proposed API look like?
Personally I have no preference over how this should look, I'm not experienced enough with vue router to say what is the most idiomatic, however I would expect to be something like the following.
The text was updated successfully, but these errors were encountered: