Watch route changes in Vue.js with Typescript Watch route changes in Vue.js with Typescript vue.js vue.js

Watch route changes in Vue.js with Typescript


I found the solution here: https://github.com/kaorun343/vue-property-decorator

It can be done like this:

   @Watch('$route', { immediate: true, deep: true })   onUrlChange(newVal: any) {      // Some action    }


This was the way for me

<script lang="ts">import Vue from 'vue'import { Route } from 'vue-router'export default Vue.extend({  name: 'HelloWorld',  watch: {    '$route': {      handler: function(to: Route): void {        // Do something here.        console.log(to)      },      immediate: true,    },  },})</script>