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>
Source:stackexchange.com