Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get route params in asyncData after router push

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` })
}
like image 820
KinIcy Net Avatar asked Nov 16 '25 01:11

KinIcy Net


1 Answers

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
    }
},
like image 191
Aldarund Avatar answered Nov 17 '25 21:11

Aldarund



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!