如何使用 Iron Router 路由到提交的 post?

How to route with Iron Router to the submitted post?

我需要在 Meteor 应用程序的服务器端提交 post。 post 提交正常,但路由器没有路由到 'problemPage',它抛出一条错误消息 - 调用 'insertProblem' 的结果传递异常:错误:路径上缺少必需的参数“/问题/:_ID”。缺少的参数是:["_id"]。传入的 params 对象是:{}。我做错了什么?

'submit form':function(event) {
    event.preventDefault();

    var post = {
    postProblem: $(event.target).find('[name=problem]').val(),
    postWhy1: $(event.target).find('[name=why1]').val(),
    postWhy2: $(event.target).find('[name=why2]').val(),
    postWhy3: $(event.target).find('[name=why3]').val(),
    postWhy4: $(event.target).find('[name=why4]').val(),
    postWhy5: $(event.target).find('[name=why5]').val(),
    postSolution:$(event.target).find('[name=solution]').val(),
    submitdate: new Date()
    };

    Meteor.call('insertProblem', post, function(result) {
        Router.go('problemPage', {_id: result._id});
      });
  }
});

Problems = new Meteor.Collection("problems");

Meteor.methods({
 insertProblem: function(post) {
  var postId = Posts.insert(post);

  return {
   _id: postId
  };
 }
});

当然还有路由器:

// redirect to the current submitted problem
Router.route('problems/:_id', {
 name: 'problemPage',
 data: function() { return Problems.findOne(this.params._id);
 }
});

router.go 应该是这样工作的。

Router.go('problemPage', result._id);

但是错误是抱怨得到一个空对象,所以让我们这样做,把 meteor.call 改成这个。

Meteor.call('insertProblem', post, function(error,result) {
        if(!error){
          console.log(result)
          console.log(result._id)
          Router.go('problemPage' + result._id); //it may work to with the + operator
        }
      });