router.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @file
  3. *
  4. *
  5. * User: marand
  6. * Date: 30/08/15
  7. * Time: 16:47
  8. */
  9. Router.configure({
  10. layoutTemplate: "layout",
  11. loadingTemplate: "loading",
  12. notFoundTemplate: "notFound",
  13. waitOn: function () {
  14. return Meteor.subscribe('posts');
  15. }
  16. });
  17. // C'est un nom de route, pas un nom de template. Mais IR le prend comme nom de template par défaut.
  18. Router.route('/', {
  19. name: 'postsList'
  20. });
  21. Router.route('/posts/:_id', {
  22. name: 'postPage',
  23. data: function () {
  24. // "this" is the matched route.
  25. return Posts.findOne(this.params._id);
  26. }
  27. });
  28. Router.route('/submit', {
  29. name: 'postSubmit'
  30. });
  31. // Faire une 404 si la page matche la route postPage, mais pas son argument.
  32. // Déclenché pour toute valeur "falsy" (null, false, undefined, empty).
  33. Router.onBeforeAction('dataNotFound', {
  34. only: 'postPage'
  35. });
  36. var requireLogin = function () {
  37. if (!Meteor.user()) {
  38. this.render('accessDenied');
  39. }
  40. else {
  41. this.next();
  42. }
  43. };
  44. // Appliquer le contrôle d'accès à la route postSubmit.
  45. Router.onBeforeAction(requireLogin, {
  46. only: 'postSubmit'
  47. });