【问题标题】:Meteor: "ReferenceError: myAdminHookFunction is not defined"流星:“ReferenceError:myAdminHookFunction 未定义”
【发布时间】:2015-10-06 09:29:04
【问题描述】:

关注 Matthew Platts 的 Meteor Tutorial

在第 4 章,部分 4.2.5 Force Login,当我实现代码时,我收到以下错误:

Your app is crashing. Here's the latest log.


/Users/TXC/.meteor/packages/meteor-tool/.1.1.3.1wysac9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
                        throw(ex);
                              ^
ReferenceError: myAdminHookFunction is not defined
    at app/both/router.js:31:23
    at app/both/router.js:33:3
    at /Users/TXC/code/foosboom-meteor/.meteor/local/build/programs/server/boot.js:222:10
    at Array.forEach (native)
    at Function._.each._.forEach (/Users/TXC/.meteor/packages/meteor-tool/.1.1.3.1wysac9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
    at /Users/TXC/code/foosboom-meteor/.meteor/local/build/programs/server/boot.js:117:5
Exited with code: 8
Your application is crashing. Waiting for file change.

更新:一切正常,直到我按照Listing 4.26: both/router.js 中的建议更新代码。

更新 2:这是 router.js 文件的内容:

Router.configure({
  layoutTemplate: 'layout',
  loadingTemplate: 'loading'
});

Router.route('/', {
  name: 'games',
  waitOn: function(){
    return [Meteor.subscribe("games"), Meteor.subscribe("teams")];
  }
});

Router.route('/teams', {
  waitOn: function(){
    return Meteor.subscribe("teams");
  }
});

var requireLogin = function(){
  if(!Meteor.user()){
    if(Meteor.loggingIn()){
      this.render("loading");
    } else {
      this.render("accessDenied");
    }
  } else {
    this.next();
  }
}

Router.onBeforeAction(requireLogin);

我检查了我的代码三遍,没有发现哪里出了问题:知道吗?

【问题讨论】:

  • 你能发布你的 router.js 文件吗?看起来问题像 31 一样。
  • 刚刚做到了。但是@JordanSpeizer 的回答解决了这个问题。感谢您的观看。

标签: javascript meteor iron-router router referenceerror


【解决方案1】:

该教程中似乎有一个错字:

Router.onBeforeAction(myAdminHookFunction, {
 only: ['admin']
 // or except: ['routeOne', 'routeTwo']
});

应该是这样的:

Router.onBeforeAction(requireLogin, {
 only: ['admin']
 // or except: ['routeOne', 'routeTwo']
});

所以 myAdminHookFunction 应该替换为 requireLogin

【讨论】:

    猜你喜欢
    • 2015-07-02
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多