Meteor Router 崩溃 - 无法调用未定义的方法 'filters'

Meteor Router crashing - Cannot call method 'filters' of undefined

我有一个页面,我希望用户无法访问,除非他们有特定的 属性。我定义了一个过滤器:

Meteor.Router.filters({ //line 24
  isX: function(page) {
    if(Roles.userIsInRole(this.userId, ['X'])) {
      return page;
    } else {
      return '/error';
    }
  }
});

Meteor.Router.filter(isX, {only : 'xPage'});

此代码存在于我的 router.js 文件中。当我尝试编译它时,出现以下错误:

\.meteor\packages\meteor-tool.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
                      throw(ex);
                            ^
    TypeError: Cannot call method 'filters' of undefined
        at app\lib\router.js:24:15
        at app\lib\router.js:70:3 //end of file
        at \.meteor\local\build\programs\server\boot.js:222:10
        at Array.forEach (native)
        at Function._.each._.forEach (\.meteor\packages\meteor-tool.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
        at \.meteor\local\build\programs\server\boot.js:117:5
    Exited with code: 8
    Your application is crashing. Waiting for file change.

我很茫然,因为这几乎是铁路由器示例中的直接内容。

关于 iron:router,我不确定你从哪里得到 Meteor.Router.filters。不过,您可以使用 onBeforeAction 做一些与您需要的非常相似的事情。

var isX = function() {
    if (Roles.userIsInRole(this.userId, ["X"])) {
        this.next();
    }
    else {
        this.redirect("/error");
    }
};

Router.onBeforeAction(isX, {
    only: ["xPage"]
});

Router.route("/xPage", {
    name: "xPage",
    action: function() {
        this.render("xPage");
    }
});