Reputation: 57
I have my directory structure kind of like this
pages/
└── _id/
├── index.vue
└── edit.vue
now I want to access the route of my folder in edit.vue but it says route is not defined
or $route is not defined
. In my created()
I use route.params.id
or $route.params.id
to a variable. But I don't think it works. How do I do this?
Upvotes: 1
Views: 992
Reputation: 3248
In the created()
lifecycle hook, you have access to the this
instance. From there you can get the id
URL param with this.$route.params.id
.
However, when using the asyncData()
API hook you don't have access to this
, but there is a context model passed in that has the params
object.
Upvotes: 1