即使页面转换,Meteor Router.go也不会更改Url

时间:2015-09-15 03:53:16

标签: javascript meteor iron-router

我有一个非常奇怪的错误。我有一个按钮的点击事件设置,它通过Router.go发送到另一个模板。但是,页面将转换,它将传递数据,但网址不会更改。所以我不能使用params进行下一次转换(这是一个注册流程)。

Template.tellUsAboutYourself.events({


'click .continueHide': function(){
    var mealsPerDay = $('.checkbox_check1:checked').val();
    var snacksPerDay = $('.checkbox_check2:checked').val();
    var typesOfSnacks = '';
    $('.checkbox_check3:checked').each(function(i){
      typesOfSnacks = typesOfSnacks + '4' + $(this).val();
    });
    var homeCooked = $('.checkbox_check4:checked').val();
    var sodaOften = $('.checkbox_check5:checked').val();
    var coffeeOften = $('.checkbox_check6:checked').val();
    var coffeeHow = $('.checkbox_check6a:checked').val();
    var juiceOften = $('.checkbox_check7:checked').val();
    var threeFoodsOften = '';
    $('.checkbox_check8:checked').each(function(i){
      threeFoodsOften = threeFoodsOften + '4' + $(this).val();
    });
    var activityLevel = $('.checkbox_check9:checked').val();

    var id = NutritionData.insert({name: this.name, last_name: this.last_name, ideal_weight: this.ideal_weight, height: this.height, current_weight: this.current_weight, gender: this.gender, age: this.age, mealsPerDay: mealsPerDay, snacksPerDay: snacksPerDay, typesOfSnacks: typesOfSnacks, homeCooked: homeCooked, sodaOften: sodaOften, coffeeOften: coffeeOften, coffeeHow: coffeeHow, juiceOften: juiceOften, threeFoodsOften: threeFoodsOften, activityLevel: activityLevel});
    console.log(id);

    Router.go('yourResults', {id: id});
  }
});

然后在router.js文件中我有以下内容:

Router.route('/yourResults/:id', {
  name: 'yourResults',
  trackPageView: true,
  layoutTemplate: false,
  data: function(){
    return NutritionData.find({_id: this.params.id}).fetch()[0]
  },
});

ID是正确的,但由于某种原因,它没有更改网址。以前有人有这个问题吗?我一直在重构大量的代码,无处不在寻找错误,但我已经没有想法了。

由于

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,它与路由器无关。在极少数情况下,任何人都会遇到同样的噩梦场景,错误是由于一个会话变量在一个帮助器内部的for循环中,特别是多次运行。这并没有给出任何错误,但它引起了各种奇怪的行为,包括路由器故障。