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);
我经历了三次代码并且没有看到出错的地方:任何想法?
答案 0 :(得分:2)
在该教程中看起来有一个拼写错误:
Router.onBeforeAction(myAdminHookFunction, {
only: ['admin']
// or except: ['routeOne', 'routeTwo']
});
应该是这样的:
Router.onBeforeAction(requireLogin, {
only: ['admin']
// or except: ['routeOne', 'routeTwo']
});
因此myAdminHookFunction应替换为 requireLogin 。