0

In vue.js route.js

[{path: "/path", name: "acomp_name", component: PathComp, props: { abc: {} }}]

comp.vue

<script>
...omitted_for_brevity,
methods: {
  changeRoute(json_sample){
     this.$router.push({name: "acomp_name", params: { abc: json_sample })
  }
}
</script>
  1. Is there a way I can set the props which is an object to return json sample which is another object, like this that is can I set the value of props of the router in a push
  2. if indeed it is not supported in vue-router4 . what approach has been used or is being used to do this?
iamcoder
  • 21
  • 5
  • Does this answer your question? [Pass an object as param to router.push (vue-router@4.05)](https://stackoverflow.com/questions/66864658/pass-an-object-as-param-to-router-push-vue-router4-05) – Michal Levý Sep 17 '21 at 19:19
  • no Sir, it does not, but seems close in the overview, the intent of my question is to even be able to see the values of props as an object being accessed in the first place, and quite honestly it returns the "[object object]", but I need to be a able to set and get like where abc can be equal json_sample say for instance {"a": "stack", 'b': "overflow"}, – iamcoder Sep 17 '21 at 19:37
  • Read it again .... **it is not possible to pass an object through route params** ! – Michal Levý Sep 17 '21 at 20:16
  • thanks I saw it well now, some last questions, do you really feel like Pinia is really good over vuex, cause I noticed vuex is a bit slow especially for context commit changes, then what other alternatives do you advise with other third-party projects that can be used alongside vue.js n a project – iamcoder Sep 17 '21 at 20:24
  • Pinia is **really good**. It's author (posva) is Vue core member and Pinia was his side-project where he explored how "Vuex next" can look like. And indeed [current RFC of Vuex 5](https://github.com/vuejs/rfcs/discussions/270) (next version of Vuex) is very much inspired by Pinia – Michal Levý Sep 17 '21 at 20:51
  • does that sound like we can still stick to vuex despite the odds since vuex is like a parent of pinia. especially with vuex5 coming forth, – iamcoder Sep 17 '21 at 20:55
  • Well, no. Vuex 4 is very different from Pinia. So if you are asking what will be easiest migration path I say Pinia to Vuex 5 will by much easier migration then Vuex 4 to Vuex 5 – Michal Levý Sep 17 '21 at 20:59

1 Answers1

0

I am grateful to God Almighty for helping me to create an intuitive and reliable answer, N<>B solution works with vue3 and vue-router4x

in the comp.vue somewhere inside the template I have a nested or child component so

    <template>
      <p>...</p>
    ...omitted_for_brevity
    <router-view :prop_from_router.js="this.state.a_key_I_want_to_use"/>
    </template>

still in comp.vue

<script>
...omitted_for_brevity
setup(){
  const s = reactive({})
  return {s}
},
methods: {
  changeRoute(t)
  this.state.a_key_i_want_to_use = t
}
}
</script>
iamcoder
  • 21
  • 5