2014-10-08 28 views
6

我有以下的路由配置:https://gist.github.com/chriswessels/76a64c421170095eb871流星铁路由器onBeforeAction this.next不确定

我得到尝试加载路由时出现以下错误:

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不确定?请帮助!

克里斯

+0

克里斯,我有同样的问题。如果我弄清楚,我会让你知道的。请为我做同样的事情。谢谢。 – CoderZen 2014-10-18 21:19:31

回答

2

你是混合了不同版本的铁路由器:

此前铁路由器1.0,onBeforeAction除非pause(被调用的第一个参数来onBeforeAction将着手行动没有.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); 
    } 
} 
+0

感谢您的回答。铁路由器API从1.0开始改变是正确的,但是有一段时间的API流量,其中暂停参数仍然与this.next一起传递到回调函数中。我相信这是0.9.4版本(当时我问这个问题)。在1.0命中之后,我将路由器设置迁移到仅使用this.next。对其他人:这涉及确保所有onBeforeAction挂钩调用this.next。暂停路线的执行是选择退出而不是像以前那样选择加入。 – chriswessels 2014-11-09 21:13:32