Meteor Iron-router onBeforeAction this.next undefined

chr*_*els 6 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)
Run Code Online (Sandbox Code Playgroud)

它正在讨论以下行,它位于onBeforeAction钩子中:

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

为什么不this.next定义?请帮忙!

克里斯

d_i*_*ble 3

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

在 Iron Router 1.0 之前,除非调用第一个参数 to ,onBeforeAction否则将继续执行操作。没有方法。pauseonBeforeAction.next()

从 1.0 开始,这一点发生了变化。pause()不再作为参数传递。这就是该.next()方法取代它的地方。

您显然正在旧版本的 Iron 路由器上运行,因此您的钩子应该如下所示:

function manageLoadingIndicator (pause) {
  if (this.ready()) {
    Session.set('loading', false);
  } else {
    Session.set('loading', true);
    pause();
  }
}
Run Code Online (Sandbox Code Playgroud)

升级 Iron Router 后,您需要将其更改为:

function manageLoadingIndicator () {
  if (this.ready()) {
    Session.set('loading', false);
    this.next();
  } else {
    Session.set('loading', true);
  }
}
Run Code Online (Sandbox Code Playgroud)