question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add onComplete & onAbort to router-link

See original GitHub issue

What problem does this feature solve?

In 2.2.0 Vue added onComplete and onAbort callbacks to router.push, however there seems to be no equivalvent when using <router-link>. I’ve seen suggestions that can you use beforeRouteEnter 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. So beforeRouteEnter would not work for my case. Ideally I’d like to be able to supply onComplete and onAbort to the router-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.

<router-link to="…" on-complete="callback" on-abort="callback"></router-link>
<!-- or -->
<router-link to="…" complete="callback" abort="callback"></router-link>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mitarcommented, Mar 28, 2022

OK, it seems that in v4, navigate returns a promise, so one can make a custom router-link which awaits on navigate and then does additional logic.

1reaction
kelunikcommented, Feb 3, 2020

Implemented by #3114.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do we have onComplete and onAbort callback using <router ...
You can add beforeRouteEnter() for called compenent. Try "Fetching Before Navigation" on vue-router documentation.
Read more >
Do we have onComplete and onAbort callback using <router ...
[Solved]-Do we have onComplete and onAbort callback using <router-link> like router.push(location, ... You can add beforeRouteEnter() for called compenent.
Read more >
API Reference | Vue Router
<router-link> is the component for enabling user navigation in a router-enabled app. ... router.push(location).then(onComplete).catch(onAbort) ...
Read more >
Programmatic Navigation of Vue Router Routes
router.push(location, onComplete?, onAbort?) To do this, we can use the $router instance ... is called when a router-link link is clicked.
Read more >
Using Vue 3's Router in Practice - Daily.dev
So let's look at how we can install Vue Router to our Vue 3 project. ... router.push(location, onComplete?, onAbort?)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found