Search code examples
javascriptmeteoriron-router

What's the correct way to create a global iron:router subscription?


I need a particular subscription for every route in my app, this works but I'm unsure if it is correct?

Router.onBeforeAction(function() {
    Meteor.subscribe('locations');
    this.next();
});

Also, is there a way to waitOn() globally?


Solution

  • You can declare any options that you can set on a route on a global level by using the Router.configure({}); . To use your example above:

    Router.configure({
        waitOn: function() {
            return Meteor.subscribe('locations');
        }
    });
    

    The above will give you the specified subscription for all routes in your application by using the waitOn option in a global route context. For more information about all of the other options that you can set for routes on a global level, check this out.