Vue.js Event Watch Route Change


We can use watch property to track the change in route change. It is very simple to use Watch Route change in vue.js. Here in this article we are going to explain how you can get the route change in Vue.js.


Vue.js Event Watch Route Change Example

You can use watch property simply as below –

Example:

<script>
 new Vue({
 el: '#app',
  
  data: { 
      // Your data
  },
  
   methods:{
      // your methods
   },
  watch:{
    $route (to, from){
        console.log(to);
        console.log(from);
    }
  } 

});
</script>      

On the same way you can track the change in Router(URL).


Advertisements

Add Comment