Created
September 9, 2014 19:16
-
-
Save wolves/a4ad2986b9ab4c0c1351 to your computer and use it in GitHub Desktop.
Iron Router using waitOn function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Router.configure({ | |
layoutTemplate: 'layout', | |
loadingTemplate: 'loading', | |
waitOn: function() { | |
return [ | |
Meteor.subscribe('posts'), | |
Meteor.subscribe('comments') | |
]; | |
} | |
}); | |
Router.map(function() { | |
this.route('postsList', {path: '/'}); | |
this.route('postPage', { | |
path: 'posts/:_id', | |
data: function() { | |
return Posts.findOne(this.params._id); | |
} | |
}); | |
this.route('postEdit', { | |
path: '/posts/:_id/edit', | |
data: function() { | |
return Posts.findOne(this.params._id); | |
} | |
}); | |
this.route('postSubmit', { path: '/submit' }); | |
}); | |
var requireLogin = function(pause) { | |
if (! Meteor.user()) { | |
if (Meteor.loggingIn()) { | |
this.render(this.loadingTemplate); | |
} else { | |
this.render('accessDenied'); | |
} | |
pause(); | |
} | |
}; | |
Router.onBeforeAction('loading'); | |
Router.onBeforeAction(requireLogin, { only: 'postSubmit' }); | |
Router.onBeforeAction(function() { clearErrors(); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment