Meteor Iron-router onBeforeAction this.next undefined

时间:2014-10-08 11:39:50

标签: meteor iron-router

我已获得以下路线配置: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钩子中:

function manageLoadingIndicator (pause) {
  if (this.ready()) {
    Session.set('loading', false);
    this.next(); // THIS LINE HERE
  } else {
    Session.set('loading', true);
    pause();
  }
}

为什么this.next未定义?求救!

克里斯

1 个答案:

答案 0 :(得分:2)

您正在混合不同版本的Iron路由器:

在铁路由器1.0之前,onBeforeAction将继续执行,除非pause(调用onBeforeAction的第一个arg。没有.next()方法。

从1.0开始,这已经改变了。 pause()不再作为参数传递。这是.next()方法替换它的地方。

你显然是在旧版本的铁路由器上运行,所以你的钩子应该是这样的:

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);
  }
}