Same route, different data, no reactivity?


#1

Hey all,

after seemingly going through the same steps as I always do in working with Iron Router, Controllers, data contexts, etc., I can’t seem to figure out why I’m lacking reactivity in my template.

Here is my route:

Router.route('/dashboard/:_id', {
  name: 'dashboard',
  controller: dashboardController,
  data: function() {
    currentOrgId = this.params._id;
  },
});

This is my controller:

dashboardController = RouteController.extend({
  layoutTemplate: 'layout',
  action: function(){
    this.render('dashboard');
  },
  waitOn: function(){
    return [
      Meteor.subscribe('myOrgs', Meteor.userId()),
    ];
  }
});

Here is the helper:

Template.dashboard.helpers({
  myOrgs: function(){
    return Orgs.find();
  },
  thisOrg: function(){
    return Orgs.findOne({_id:currentOrgId}).name;
  },
});

And finally, the route call from my “change #mySelect

Router.go('dashboard', {_id: e.target.value}); 

When I change the select, I get the correct url, with the updated _id, but the helper data doesn’t change. On a refresh, I get the appropriate data.

Not sure what I’m missing here – hopefully someone can see what I’m missing!

Thanks in advance!


#2

You’re not returning anything in the data function?


#3

I think he does not want to pass there anything, just assign global variable, what could be done also in action.
But as it is not session or reactive variable, helper does not recompute as it changes.


#4

@shock not really how data should be used :smile:
@vigorwebsolutions FYI you can just access the params like this


#5

@hellstad Thanks – I had an issue before accessing the params in the helper, so I started creating globals in the router, which I realize now is not correct.

@shock After setting the a Session variable equal to the Router.current().params._id, all is good when I reference that. Thanks!