[Navigation Guard - Vue setup] onBeforeRouteUpdate not working when using the same component for different routes #2007
-
This is part of my route file, where I have registered component Any helps or suggestions would be highly appreciated. Thanks all!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
beforeUpdate is only for the same route, e.g. one param to another. You can use a global import { onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
function onBeforeNavigation(fn) {
const router = useRouter()
const remove = router.beforeEach(fn)
onUnmounted(remove)
} For now, you can add this to your codebase |
Beta Was this translation helpful? Give feedback.
beforeUpdate is only for the same route, e.g. one param to another. You can use a global
router.beforeEach()
. Ideally, new hooks should be added to play well with the composition API:For now, you can add this to your codebase