user1037355
user1037355

Reputation:

Access the router params from within typescript vue component class

how can i access the params of the vue router within a typescript vue class?

See the screenshot attached, typescript complains.. are there some types i need to install?

enter image description here

The only way i can seem to get this working is to: 1 - import the router as illustrated in the image 2 - access the params via string literals:

router['history'].current.params.hash

But this breaks the linter

object access via string literals is disallowed

And rightly so, i don't want to remove this rule.

Upvotes: 2

Views: 4148

Answers (1)

slumbergeist
slumbergeist

Reputation: 1538

Vue-router provides another $route object to represent the state of the current route. So, if you need to access the params of the route you need to use this.$route.params instead of this.$router.

Also, you need not install any types as vue-router already comes with its types definition.

Upvotes: 3

Related Questions