Meteor Iron-router onBeforeAction this.next undefined

I have the following route configuration: https://gist.github.com/chriswessels/76a64c421170095eb871

When I try to load a route, I get the following error:

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) 

He talks about the following line, which is in the onBeforeAction hook:

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

Why is this.next undefined? Help me please!

Chris

+6
source share
1 answer

You are mixing different versions of Iron router:

Prior to the iron router 1.0, onBeforeAction will act if there is no pause (the first argument to onBeforeAction called. There is no .next() method.

Starting with version 1.0, this has been changed. pause() no longer passed as an argument. Here the .next() method replaces it.

You are obviously working on an old version of an iron router, so your hook should look like this:

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

Once you upgrade your iron router, you need to change it to this:

 function manageLoadingIndicator () { if (this.ready()) { Session.set('loading', false); this.next(); } else { Session.set('loading', true); } } 
+2
source

Source: https://habr.com/ru/post/976420/


All Articles