Naming Routes using Iron Router in Meteor

By default, Iron Router will look for a template with the same name as the route name. In fact, it will even infer the name from the path you provide.

You may be wondering why we even need to name our routes in the first place. Naming routes let us use a few Iron Router features that make it easier to build links inside our app. The most useful one is the {{pathFor}} Spacebars helper, which returns the URL path component of any route.

So instead of specifying a static / URL, we can also use the Spacebars helper.The end result will be the same, but this gives us more flexibility since the helper will always output the right URL even if we later change the route’s path in the router.


[cc lang=”javascript”]


When you run your App, you’ll notice that the page appears empty for a few moments before the content appear. This is because when the page loads there no actual content to display until database subscription in done grabbing the data from the server.

It would be a much better user experience to provide some visual feedback that something is happening and that the user should wait a moment.

Iron Router gives us an easy way to do just that: we can ask it to wait on the subscription.


[cc lang=”javascript”]
layoutTemplate: ‘layout’,
waitOn: function() { return Meteor.subscribe(‘posts’); }
Router.route(‘/’, {name: ‘postsList’});

What we are saying here is that for every route on the site, we want to subscribe to the posts subscription.



, ,



One response to “Naming Routes using Iron Router in Meteor”

  1. Thank you very much for sharing. Your article was very helpful for me to build a paper on After reading your article, I think the idea is very good and the creative techniques are also very innovative. However, I have some different opinions, and I will continue to follow your reply.

Recent Post

Click to Copy