Skip to content

[Navigation Guard - Vue setup] onBeforeRouteUpdate not working when using the same component for different routes #2007

Closed Answered by posva
JasmineLaiHua asked this question in Help and Questions
Discussion options

You must be logged in to vote

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:

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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JasmineLaiHua
Comment options

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants