Router.configure({ layoutTemplate: 'layout', loadingTemplate: 'loading', notFoundTemplate: 'notFound', waitOn: function () { return [ Meteor.subscribe('notifications') ]; } }); PostsListController = RouteController.extend({ template: 'postsList', increment: 5, postsLimit: function () { return parseInt(this.params.postsLimit) || this.increment; }, findOptions: function () { return { sort: this.sort, limit: this.postsLimit() }; }, subscriptions: function () { this.postSub = Meteor.subscribe('posts', this.findOptions()); }, posts: function () { return Posts.find({}, this.findOptions()); }, data: function () { var hasMore = this.posts().count() === this.postsLimit(); return { posts: this.posts(), ready: this.postSub.ready, nextPath: hasMore ? this.nextPath() : null }; } }); NewPostsController = PostsListController.extend({ sort: { submitted: -1, _id: -1 }, nextPath: function () { return Router.routes.newPosts.path({ postsLimit: this.postsLimit() + this.increment }); } }); BestPostsController = PostsListController.extend({ sort: { votes: -1, submitted: -1, _id: -1 }, nextPath: function () { return Router.routes.bestPosts.path({ postsLimit: this.postsLimit() + this.increment }); } }); Router.route('/posts/:_id', { name: 'postPage', waitOn: function () { return [ Meteor.subscribe('comments', this.params._id), Meteor.subscribe('singlePost', this.params._id) ]; }, data: function () { // "this" is the matched route. return Posts.findOne(this.params._id); } }); Router.route('/posts/:_id/edit', { name: 'postEdit', waitOn: function () { return Meteor.subscribe('singlePost', this.params._id); }, data: function () { // "this" is the matched route. return Posts.findOne(this.params._id); } }); Router.route('/submit', { name: 'postSubmit' }); // C'est un nom de route, pas un nom de template. Mais IR le prend comme nom de // template par défaut. Router.route('/', { name: 'home', controller: 'NewPostsController', }); Router.route('/new/:postsLimit?', { name: 'newPosts' }); Router.route('/best/:postsLimit?', { name: 'bestPosts' }); var requireLogin = function () { if (!Meteor.user()) { if (Meteor.loggingIn()) { // Défini dans Router.configure(). this.render(this.loadingTemplate); } else { this.render('accessDenied'); } } else { this.next(); } }; // Faire une 404 si la page matche la route postPage, mais pas son argument. // Déclenché pour toute valeur "falsy" (null, false, undefined, empty). Router.onBeforeAction('dataNotFound', { only: 'postPage' }); // Appliquer le contrôle d'accès à la route postSubmit. Router.onBeforeAction(requireLogin, { only: 'postSubmit' });