I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params.
this is my asynData method:
async asyncData(ctx) {
const { id } = ctx.app.router.currentRoute.params
await ctx.store.dispatch('user/GET_USER', id)
return {
user: ctx.store.state.user.user
}
},
and this is how I navigate to the respective page:
goToEdit(id) {
this.$router.push({ path: `/users/${id}/edit` })
}
You need to get route from ctx directly. Here a list of context arguments
async asyncData({ route }) {
const { id } = route.params
await ctx.store.dispatch('user/GET_USER', id)
return {
user: ctx.store.state.user.user
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With