router.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. FlowRouter.route('/', {
  2. name: 'home',
  3. triggersEnter: [AccountsTemplates.ensureSignedIn],
  4. action: function() {
  5. EscapeActions.executeAll();
  6. Filter.reset();
  7. Session.set('currentBoard', '');
  8. BlazeLayout.render('defaultLayout', { content: 'boardList' });
  9. }
  10. });
  11. FlowRouter.route('/b/:id/:slug', {
  12. name: 'board',
  13. action: function(params) {
  14. let currentBoard = params.id;
  15. // If we close a card, we'll execute again this route action but we don't
  16. // want to excape every current actions (filters, etc.)
  17. if (Session.get('currentBoard') !== currentBoard) {
  18. EscapeActions.executeAll();
  19. }
  20. Session.set('currentBoard', currentBoard);
  21. Session.set('currentCard', null);
  22. BlazeLayout.render('defaultLayout', { content: 'board' });
  23. }
  24. });
  25. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  26. name: 'card',
  27. action: function(params) {
  28. Session.set('currentBoard', params.boardId);
  29. Session.set('currentCard', params.cardId);
  30. EscapeActions.executeUpTo('popup-close');
  31. BlazeLayout.render('defaultLayout', { content: 'board' });
  32. }
  33. });
  34. FlowRouter.notFound = {
  35. action: function() {
  36. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  37. }
  38. }
  39. // We maintain a list of redirections to ensure that we don't break old URLs
  40. // when we change our routing scheme.
  41. var redirections = {
  42. '/boards': '/',
  43. '/boards/:id/:slug': '/b/:id/:slug',
  44. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId'
  45. };
  46. _.each(redirections, function(newPath, oldPath) {
  47. FlowRouter.route(oldPath, {
  48. triggersEnter: [function(context, redirect) {
  49. redirect(FlowRouter.path(newPath, context.params));
  50. }]
  51. });
  52. });