0

newbie Nuxt question:

I try to redirect to the same route with a different param, and have no idea how to use $nuxt to push the route so I tried the below vue router.

The url is changed but mounted hook does not get invoked to change the data

methods: {    
  changeMatch(event) {
 
  this.$router.push({
    name: "tran-dau-id-tuong-thuat",
    params: { id: event.target.value },
  });
},

Update: I follow https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes

watch: {
    $route(to, from) {
      if (to.params.id != from.params.id) {
        this.loadFixture();
      }
    },
  },
nam vo
  • 3,271
  • 12
  • 49
  • 76

1 Answers1

2

You have to watch the router param for changes.

watch: {
  id(newId) {
    // has changed call mounted logic again ...
    this.getDataAgainLogic(newId) ... 
  }
}

Vue Router Documentation: Reacting to Params Changes

ColiZei
  • 21
  • 3