我正在运行铁路由器1.0.7,我的onBeforeAction
挂钩导致异常。这是堆栈跟踪:
Exception in callback of async function: TypeError: object is not a function
at Router.onBeforeAction.except (http://localhost:3000/lib/router.js?ebfe803416134e7c5b16265486b3998532289c58:45:8)
at http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:1199:36
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at Router.addHook.hookWithOptions (http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:1198:27)
at boundNext (http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:424:31)
at Meteor.bindEnvironment (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:983:22)
at Router.onBeforeAction.only (http://localhost:3000/lib/router.js?ebfe803416134e7c5b16265486b3998532289c58:28:12)
at http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:1199:36
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at Router.addHook.hookWithOptions (http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:1198:27)
以下是引用的钩子:
Router.onBeforeAction(function () {
//check if it's a logged in user
if (!Meteor.userId()) {
//if they aren't redirect them to login
this.render('login');
} else {
//if they are let them through
this.next();
}
},
//the routes we want this if logged in check for
{only: ['profile', 'logout', 'users']
});
// Redirects users to the survey until they have answered all the questions
Router.onBeforeAction(function() {
Meteor.subscribe('questions');
var answered = getUserAnswers();
var unanswered = Questions.find({ _id: { $nin: answered } }, {sort: {priority: 1}}).count();
if (unanswered && Roles.userIsInRole(Meteor.user(), 'manage-users')) {
this.next();
} else if (unanswered) {
this.redirect('survey');
}
this.next();
},
{except: ['survey', 'passwordReset', 'logout', 'settings', 'login']});
这似乎是导致异常的最后一个this.next()
(这是跟踪第一行中引用的行。)但我无法说明原因。如果我在DevTools中设置断点,它会运行两次就好了。然后,在第三站,next
未定义。知道为什么会这样吗?尽管有例外,这些路线似乎仍能正常工作。