[Vuejs]-Vue-router shared component with route params changes to filter results

0👍

You can use the beforeRouteUpdate in-component guard:

beforeRouteUpdate: (to, from, next) {
  next(store.getters['ants/filter'](to.params.filter))
}

0👍

An alternate way would be to use this:

Note: Put this code on the same level as created: { }, methods: { } etc

watch: {
  '$route' (to, from) {
    // Your code.
  }
}

Route guards are better but if you’re finding you need to use lots of them and call the same code then this could work instead as it reacts to any route changes.

Leave a comment