title: Run method before route
body: <p>I have a login modal that I activate by setting <code>.is-active</code> to it. For this, I have a method like this:</p>
  
  <pre><code>methods: {
      toggleModal: function (event) {
        this.isActive = !this.isActive
      }
    }
  </code></pre>
  
  <p>that I run onclick. Depending on the boolean value of <code>isActive</code>, my modal gets the class <code>.is-active</code>.</p>
  
  <p>Thing is, in my modal I have a button that takes the user to a new view which means it's rendering a new component, with this code:</p>
  
  <p><code>&lt;router-link class="control" @click="toggleModal()" to="/register"&gt;</code></p>
  
  <p>As you can see, it's routing to <code>/register</code>. Before doing this, I need to run <code>toggleModal()</code> so that the modal gets closed. Right now it's routing without running the method which means that the new view has my modal overlay which is... not optimal.</p>
  
  <p>Is there any good way to do this in Vue? Could I maybe create a method, that first calls <code>toggleModal()</code>, and then routes from the method?</p>
  
  <p>Thanks.</p>