Skip to content

watching route doesn't fire with composition api #7239

Discussion options

You must be logged in to vote

Perhaps you should use

setup(){
      const router = useRouter()
      watch(
        () => router.currentRoute.value,
        currentRoute=> {
             console.log(currentRoute.path)
        },
        { immediate: true }
      )
}

useRoute() returns the current route location. The reason why this.$route can be used in vue2 is because this points to the root, so the latest ones are obtained.

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@chenxch
Comment options

@chenxch
Comment options

@gregorvoinov
Comment options

@chenxch
Comment options

@gregorvoinov
Comment options

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