在 Meteor 应用程序的服务器端使用 Iron Router?

Using Iron Router on Server Side of Meteor Application?

我尝试调用 Router.go('confirmation') 在信息被插入数据库后将用户带到确认页面。

Meteor.methods({
    'createNewItinerary': function(itinerary){
      var userId = Meteor.userId();
      ItineraryList.insert({
        [....values.....]
      },function(){
        Router.go('confirmation'); 
      });

    }

在服务器控制台中,我得到响应:has no method 'go'

数据插入成功,如何让它路由到确认页面?

-- 编辑--

这行得通吗?好像是不知道怎么验证:

Meteor.call('createNewItinerary',itinerary, function(err, data){
       if(err){
         console.log(err);
       }
       else Router.go('confirmation');
     });

你的建议对我来说很有意义:

Meteor.call('createNewItinerary',itinerary, function(err, data){
   if(err){
     console.log(err);
   }
   Router.go('confirmation');
 });

您将调用 createNewItinerary,然后 returns 您会将用户发送到确认页面。就是说,您可能需要一些错误检查 - 因为您目前已经掌握了它,所以无论插入成功还是失败,您都会将用户发送到确认页面。也许:

Meteor.call('createNewItinerary',itinerary, function(err, data){
   if(err){
     console.log(err);
     Router.go('errorpage'); // Presuming you have a route setup with this name
   }
   else Router.go('confirmation');
 });

您的建议是不错的选择。 您无法在 Meteor 方法中捕获 Router,因为它在服务器端。您必须在 回调函数 中执行此操作,就像您建议的那样:

Meteor.call('createNewItinerary',itinerary, function(err, data){
   if(err){
     console.log(err);
   }
   Router.go('confirmation');
 });

要检查服务器上的工作是否正确完成,只需抛出错误,例如:

 throw new Meteor.Error( 500, 'There was an error processing your request' );

然后如果抛出错误,它将被记录在您的客户端。

希望对你有帮助:)