-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Router link reloads the app when @click handler is added #846
Comments
If you add a We could instead combine the routerlink |
Thanks @posva! I have finally been able to implement what I wanted with custom router link: <router-link :to="{name: routeName}" :custom="true" v-slot="{href, navigate}">
<a :href="href" @click="onLinkClick($event, navigate)">
{{ text }}
</a>
</router-link> I tried this approach before. I just forgot to pass setup(props, context) {
const {myCondition} = toRefs(props);
const onLinkClick = (event: MouseEvent, navigate: (event: MouseEvent) => void) => {
if (myCondition.value) {
event.preventDefault();
} else {
navigate(event);
}
context.emit('link-click');
};
return {onLinkClick};
}, But it would still be nice if it was possible to simply add |
@livthomas Thanks for the implement. This is my wrapped version. Hope it help someone.
|
If I understand correctly, there is no need for So the solution is just to remove |
Version
4.0.5
Reproduction link
https://codesandbox.io/s/magical-maxwell-9ssoy?file=/src/App.vue
Steps to reproduce
See where
@click
event handler has been added to<router-link>
and try to click on that link.What is expected?
Vue Router should take you to a given page without a full application reload.
What is actually happening?
The whole application is reloaded as if it was a regular HTML link.
Based on specific values of component props, we sometimes need to both prevent the default router link action and execute a custom logic instead. This bug makes it impossible to do that.
The text was updated successfully, but these errors were encountered: