I can't figure out how to watch routes in Nuxt3.
In Nuxt2 was very easy to make it in any component. Did anyone knows how can i write this in Nuxt3?
<script>
export default {
....
watch: {
$route(to, from) {
console.log('route change to', to)
console.log('route change from', from)
},
},
....
}
</script>
The "myvariable" either can be boolean or string or whatever.
<script setup>
const myvariable = ref(true)
watch(
() => route.path,
() => {
do my function or
myvariable.value = false
},
);
The "myvariable" either can be boolean or string or whatever.
Got it
<script lang="ts" setup>
const menu = reactive({isOpen: false});
const route = useRoute();
watch(route, value => {
menu.isOpen = false
}, {deep: true, immediate: true})
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With