I am wondering if there is a way to use a library or other custom function within the router.js file (using iron-router) for a meteor app.
The code is like this:
Router.map(function() {
this.route('editorder', {path: '/editorder/:_id', template:'editorder',
data: function() {
if(this.params._id == 'new')
return OrderFactory.newOrder();
else
return OrderFactory.getOrder(this.params._id);
}
});
}
The only way I can get this to work is to define the OrderFactory above this call to Router.map (ie. within the router.js file). Does meteor have a way to bootstrap some code before it runs any of its own initialization? I would like to use OrderFactory within router.js and also elsewhere.
Thanks for any help!
Update / Solution: The issue was that I was defining the OrderFactory with the 'var' keyword. Changing it to:
OrderFactory = { ... };
solved the problem. This is related to specifics about Meteor namespacing, described here: http://docs.meteor.com/#/full/namespacing