[Vuejs]-Close menu after changing route: VueJs3 + Tailwind (vue-router)

1👍

Just add a watcher over the router to close the menu whenever the current route changes:

watch: {
  '$route.path'() {
    this.showMenu = false
  }
}

0👍

<router-link @click="toggleNav" to="$path">Home</router-link>

or

<template>
  <button @click="redirectHandler($path)">Home</button>
</template>

<script>
    methods:{
           redirectHandler(path) {
                 this.showMenu = !this.showMenu
                 this.$router.push(path)
              }
            }

</script>
    
👤jovan

Leave a comment