Skip to content
Discussion options

You must be logged in to vote

The usual approach is to watch route.params.id and fetch the new data when it changes.

const route = useRoute()

watch(
  () => route.params.id,
  (id) => {
    fetchUser(id)
  },
  { immediate: true }
)

onBeforeRouteUpdate() is also useful when you need to perform navigation-specific logic, but for simply reacting to a changed route parameter, watching the parameter is usually the cleanest option.

I wouldn't force a remount with key unless you specifically need the component's entire state to reset.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by niazahmeducc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants