Reputation: 281
i'm a novice in nuxtjs. I have a following structure:
pages/
--| items/
-----| /info
---------| _slug.vue
I have a route 'website/items/info/39dj83'.
Where '39dj83' is a dynamic variable, that i got from API.
How can i redirect user to that route?
I'm trying something like this:
this.$router.push({name : 'items-info-slug', ???});
How can i send a slug '39dj83'??
Is my structure corrent?
Also how can i get this slug '39dj83' in my slug.vue component?
Upvotes: 0
Views: 5334
Reputation: 17621
this.$router.push({name : 'items-info-slug',params: { slug: '39dj83' }});
In your _slug.vue you can access it via params. E.g.
fetch({params}) {
console.log(params.slug)
}
Upvotes: 2
Reputation: 1
Since you use a data that you got from your API; your structure should look like this:
pages/
--| items
-----| info
---------| _slug
--------------| index.vue
_slug is a folder, and index.vue contains the template, script and style that you had put in _slug.vue before.
To do redirection:
methods: {
goToSlugItem() {
//not sure, it depends on your code
this.$router.push("/items/info/_${item.slug}")
}
}
Sorry for my bad english, hope it helped.
Upvotes: 0