Send Object from one template to another via iron router, meteor

41 views Asked by At

I am getting some data on a template via meteor.call. Now I want to send the object to another template. I am using iron:router for routing. Below is my code :

Meteor.call(functionName, function(err, res){
    if(!err){
      //do something
      Router.go('templateName', {
        data : res
      });
    } 
});


Router.route('/url/:data?', function(){
    console.log(this.params.data);
})

In the console.log, I am getting the object as string. Data returned is

"object Object"        => (this is a string, not an object)

I don't want to use Session variables as they are global. I am confused as to how to send data from one template to another. The templates are not related to each other (parent-child relation) and hence I can't use {{>templateName data=this}}

I also tried using query parameters as suggested by @Jankapunkt

Router.go('templateName', {},{
    query : res
});

Router.route('/url/:data?', function(){
    console.log(JSON.stringify(this.params.query));
});

Printed statement :

{"0":"[object Object]","1":"[object Object]","2":"[object Object]","3":"[object Object]","4":"[object Object]","5":"[object Object]","6":"[object Object]","7":"[object Object]","8":"[object Object]","9":"[object Object]","10":"[object Object]","11":"[object Object]","12":"[object Object]","13":"[object Object]","14":"[object Object]"}

Any idea on how to proceed?

0

There are 0 answers