我有以下路由配置:https://gist.github.com/chriswessels/76a64c421170095eb871
尝试加载路线时出现以下错误:
Exception in defer callback: TypeError: undefined is not a function
at manageLoadingIndicator (http://localhost:3000/both/router/routes.js?ef701fada29363a443a214f97988ce96ebaec025:30:10)
at RouteController.runHooks (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:843:16)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:2302:14
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:2279:12
at Utils.extend._run.withNoStopsAllowed (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:2248:21)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
谈论的是以下行,该行位于onBeforeAction Hook 中:
function manageLoadingIndicator (pause) {
if (this.ready()) {
Session.set('loading', false);
this.next(); // THIS LINE HERE
} else {
Session.set('loading', true);
pause();
}
}
为什么
this.next
未定义?请帮助!克里斯
最佳答案
您正在混淆Iron路由器的不同版本:
在Iron Router 1.0之前,除非onBeforeAction
(调用pause
的第一个arg。除非存在onBeforeAction
方法,否则.next()
将继续起作用。
从1.0开始,此设置已更改。 pause()
不再作为参数传递。这是.next()
方法替换它的地方。
您显然正在旧版本的Iron Router上运行,因此您的钩子(Hook)应如下所示:
function manageLoadingIndicator (pause) {
if (this.ready()) {
Session.set('loading', false);
} else {
Session.set('loading', true);
pause();
}
}
升级铁路由器后,需要将其更改为此:
function manageLoadingIndicator () {
if (this.ready()) {
Session.set('loading', false);
this.next();
} else {
Session.set('loading', true);
}
}