我有一个页面,我希望用户无法访问,除非他们有某个属性。我已经定义了一个过滤器:
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.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.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.
我很茫然,因为这与铁路由器的例子非常相似。
答案 0 :(得分:1)
我不确定Meteor.Router.filters
对iron:router
的评价。{1}}。您可以使用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");
}
});