将 Meteor iron-router 中的 onBeforeAction 钩子移动到不同的文件

Move onBeforeAction hook in Meteor iron-router to different file

我使用以下函数作为我的 onBeforeAction 挂钩的助手:

var gameFilter = function () {
    this.subscribe('singleGame', this.params.slug);
    var game = this.data();
    if (game) {
        if (game.multiplayer) {
            this.redirect('multiPlayerPage', {slug: this.params.slug});
        } else {
            this.subscribe('singlePlayerPage', this.params.slug);
        }
    } else {
        this.render(this.notFoundTemplate);
    }
    this.next();
};

我在我的路线中这样使用它:

onBeforeAction: [gameFilter, playerFilter]

现在这太棒了。但是,我想将所有过滤器移动到不同的文件。所以我在我的 lib 目录中创建了一个新文件,并将以下代码放入:

gameFilter = function () {
    this.subscribe('singleGame', this.params.slug);
    var game = this.data();
    if (game) {
        if (game.multiplayer) {
            this.redirect('multiPlayerPage', {slug: this.params.slug});
        } else {
            this.subscribe('singlePlayerPage', this.params.slug);
        }
    } else {
        this.render(this.notFoundTemplate);
    }
    this.next();
};

问题是,我得到一个 ReferenceError,说 gameFilter 没有定义。我认为这个问题是由 Meteor 的文件加载顺序引起的。有可能解决这个问题吗?

我对 Meteor 也有类似的问题。解决方法是将文件或文件夹的名称更改为数字,以便首先加载它。就我而言,它是一个名为 media.js 的文件,我更改为 1_media.js 并且有效