[Vuejs]-How to pass a data from a component to other route in VueJS

2👍

From what I understand, this seems to be a good case for using a store like Vuex: https://vuex.vuejs.org/guide/#the-simplest-store.

It offers a structure for what you are trying to achieve by sharing a state with all the components.

Since it seems tightly coupled, it will probably be easier than trying to communicate between pages in a way that will probably be hard to maintain.

edit: I found since this answer that Vuex is not the recommended solution anymore.

It is now Pinia that is recommended. For anyone wanting to add a store to a Vue.js application, it might be a better choice.

https://pinia.vuejs.org/

1👍

I think you should just use the VueX store.
Keeping your data there would be the cleanest solution.

But if you absolutely have to use a router, you could pass your data as route params:

// Routing to other page  
this.$router.push({  
    name: 'Name_Of_The_Other_Page',  
    params: { myData: 'Your data here' }  
});

// Accessing params on the other page  
let myData = this.$route.params.myData

Leave a comment