Property 'history' does not exist on type 'VueRouter' in vue-ts

Viewed 824

I am using typescript vue in an application, I have this error coming from a component where i tried accessing a parameter passed into the route like this

  properties = getModule(PropertiesModule, this.$store);
  mounted() {
    id = this.$router.history.current.params.id;
    this.properties.getProperty(id);
  }
  get months() {
    return this.$store.state.app.months;
  }
  get property() {
    return this.$store.state.properties.property;
  }
}

The code runs perfectly fine because to the best of my knowledge this is not a malpractice. but the typescript is still throwing errors. I tried using the es-lint disable-next-line but it did not work. I also tried giving the router in my main.ts the type of any but it did not work as well. Is there a better way to access router parameters in vue.js than this?

the image of the error gotten from typescript.

1 Answers

You can get params using $route.params in Vue.js.

If you want get id param, this could work out.

this.$route.params.id
Related