[Vuejs]-VueJS router-link doesn't update component content

3👍

This may be normal, because this component is not destroyed, but the $route parameters have changed.

So you can watch the $route for params.category_name changed

watch: {
  // when redirect to new category_name, this will be callback
  '$route': (new, old) => {
     if (new.params.category_name !== old.params.category_name) {
        // reload data, same with created()
     }
  }
}

see more: https://router.vuejs.org/guide/advanced/data-fetching.html#fetching-after-navigation

👤joaner

0👍

I would prefer to use the watch lifecycle in Vue.js.

Basically what is does is watching your route and when it changes you can tell it to run a function.

example:

  watch: {
// call again the method if the route changes
        '$route': 'initService'

}

Leave a comment