vue3 - Update state in onBeforeRouteUpdate()

Viewed 16

I'm a newbie and working with translation software, thanks for the guidance.

I have a routing component that updates count in onBeforeRouteUpdate() every time I navigate, it works fine, but the onUpdated() hook is called twice, I don't understand why, is there any way to avoid it

code:

<template>
  <div>{{count}}</div>
</template>

<script setup>
import { ref, onUpdated } from 'vue'
import { onBeforeRouteUpdate } from 'vue-router'

const count = ref(0)
onUpdated(() => console.log('updated'))

onBeforeRouteUpdate((to, from) => {
  count.value += 1
})
</script>

output twice in the console [1]: https://i.stack.imgur.com/bfCEx.png

0 Answers
Related