Iron Router Problem


#1

After taking latest meteor update into my project. The iron Router is not working properly. When i ever i try use Router.go method for second time , it doesnt respond. Partial template will be loaded always. When i click in browser back button the actual template loads. This was working before the meteor 1.0 update, after the update it stopped working

`indent preformatted text by 4 spaces`Router.configure({
  layoutTemplate: 'master_layout',
  loadingTemplate: 'loading'
});



`indent preformatted text by 4 spaces`Router.map(function () {
  this.route('home', {
    path: '/',
    name:'home',
    template: 'home_page',
    waitOn: function () {     
        this.subscribe('user_portfolio_related_entities' ).wait(); 
       
        this.subscribe('user_activities_by_user_id', Meteor.userId()).wait();
        
    },


this.route('deal_detail', { 
    path: '/deal/:_id/:_id_type?',
    name:'deal_detail',
    layoutTemplate: 'tombstone_master',
    template: 'deal_detail',
    yieldTemplates: {
      'related_results_list': {to: 'related_results'},
    },
    notFoundTemplate: 'item_not_found',
    waitOn: function () {
      debugger;
      console.log('line 307');
        var params_dict = {};
        params_dict[this.params._id_type] = this.params._id;
        console.log('deal detail',params_dict);
        this.subscribe('deal_detail', params_dict).wait();
    },
    data: function() {
      debugger;
      console.log('line 307');
      var params_dict = {}
      var id_value  = this.params._id;
      var id_type = this.params._id_type;
      params_dict[id_type] = id_value;
      console.log('line 319 ===== ',params_dict);
       var temp_deal =  Deals.findOne(params_dict);
      
      if(!temp_deal) return '';
       

      return temp_deal;
    },

});
});


#2

When you upgraded to meteor1.0 you probably also got a newer iron-router which “broke” your already broken code. You are mixing up syntax for waitOn vs. subscribe code in the iron-router docs. Not sure if this will fix your problem

don’t need the wait() on the subscribe in waitOn:
this.subscribe(‘deal_detail’, params_dict)

the docs suggest usage of Meteor subscribe in the waitOn instead:
return Meteor.subscribe(‘deal_detail’, params_dict)

I wouldn’t pass an object when not neccessary so:
return Meteor.subscribe(‘deal_detail’, this.params._id)

waitOn: function () {
    Meteor.subscribe('deal_detail', this.params._id)
},
data: function() {
  temp_deal = Deals.findOne({this.params._id_type : this.params._id });
  if(!temp_deal) return '';
  else return temp_deal;
},

#3

It dint fix the issues … Router.go does not get triggered at all for the second time.


#4

When my Router.go('zzz') doesn’t work (which happens a lot, especially in event handlers), I use Meteor.defer(function() { Router.go('zzz'); }) and it fixes the issue.


#5

I’d suggest comparing what you wrote carefully against the iron-router docs and example. If still no love then post your updated code and some screenshots of what is happening.

It could be that your subscription isn’t returning ready. Also which route isn’t working? Any errors in the console?


#6

This fix worked. Router go method is getting triggered .