S
S
slagoris2021-08-06 09:51:21
Vue.js
slagoris, 2021-08-06 09:51:21

How to close modal when clicking in router-link?

Hello. I don't know much about vue yet.
There is a link in the modal. <router-link to="/privacy" >ТЕКСТ</router-link>

The modal should be closed by clicking on this link - like this.
@click="$store.commit('hideModal')",
but you also need to follow the link.
When I do it like this

<router-link to="/privacy" @click="$store.commit('hideModal')">ТЕКСТ</router-link>

we follow the link, and accordingly the @click is not processed, because event we have a link. How to make it work on vue? Please help. I think there is something simple, but I don't know how to do it yet. Probably somehow through methods. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin B., 2021-08-06
@slagoris

You can not use a router-link, but call via $router.push('/privacy') in the click handler after opening the modal
To cancel the transition, there is @click.prevent

D
Dmitry Kuznetsov, 2021-08-06
@dima9595

If you want to open a modal, then why use routing? make the same button, put the method of opening the modal there and that's it - it works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question