Meteor 铁路由器除了故障?

Meteor 铁路由器除了故障?,meteor,routing,iron-router,Meteor,Routing,Iron Router,所以我刚刚开始使用iron router,我一直在构建一个登录系统。它在每个路由之前通过.onBeforeAction钩子工作,检查用户是否登录。然而,有一些路线我想公开,所以我添加了一个例外选项,根据文档。但问题是它不起作用:(有人知道为什么吗 Router.route('/new', function () { name: 'new', this.render('newComp'); }); Router.route('/c/:_id', { name: 'compPage'

所以我刚刚开始使用iron router,我一直在构建一个登录系统。它在每个路由之前通过.onBeforeAction钩子工作,检查用户是否登录。然而,有一些路线我想公开,所以我添加了一个例外选项,根据文档。但问题是它不起作用:(有人知道为什么吗

Router.route('/new', function () {
  name: 'new',
  this.render('newComp');
});

Router.route('/c/:_id', { 
  name: 'compPage',
    data: function() { return Comps.findOne(this.params._id); }
});


Router.route('/c/:_id/embed', function () {
  name: 'embed',
  this.layout('empty'),
  this.render('compEmbed', {
    data: function () {
      return Comps.findOne({_id: this.params._id});
    }
  });
});

function loginFunction(){
  // all properties available in the route function
  // are also available here such as this.params

  if (!Meteor.user()) {
    // if the user is not logged in, render the Login template
    if (Meteor.loggingIn()) {
      this.render(this.loadingTemplate);
    } else {
      this.layout('empty');
      this.render('login');
    }
  } else {
    // otherwise don't hold up the rest of hooks or our route/action function
    this.next();
  }
}

Router.onBeforeAction( loginFunction, { 
  except: ['embed'] // this aint working
});

问题似乎出在您的路由定义中,名称param应该位于Router.route()的第三个参数中,如下所示(因此您的路由实际上没有名称,因此
除了:['route.name']
无效):


此处有关命名路由的更多信息:

问题似乎出在路由定义中,名称参数应位于Router.route()的第三个参数中,如下所示(因此您的路由实际上没有名称,因此
除了:['route.name']
无效):

有关命名路由的详细信息,请单击此处:

Router.route('/c/:_id/embed', function () {
  this.layout('empty'),
  this.render('compEmbed', {
    data: function () {
      return Comps.findOne({_id: this.params._id});
    }
  });
}, {
  name: 'embed',
});