2

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

doh! I missed that, was going around in circles. Thank you very much :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.