2014-10-08 129 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

相關問題