router.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. let previousPath;
  2. FlowRouter.triggers.exit([({path}) => {
  3. previousPath = path;
  4. }]);
  5. FlowRouter.route('/', {
  6. name: 'home',
  7. triggersEnter: [AccountsTemplates.ensureSignedIn],
  8. action: function() {
  9. EscapeActions.executeAll();
  10. Filter.reset();
  11. Session.set('currentBoard', null);
  12. Session.set('currentCard', null);
  13. BlazeLayout.render('defaultLayout', { content: 'boardList' });
  14. }
  15. });
  16. FlowRouter.route('/b/:id/:slug', {
  17. name: 'board',
  18. action: function(params) {
  19. let currentBoard = params.id;
  20. // If we close a card, we'll execute again this route action but we don't
  21. // want to excape every current actions (filters, etc.)
  22. if (Session.get('currentBoard') !== currentBoard) {
  23. EscapeActions.executeAll();
  24. }
  25. Session.set('currentBoard', currentBoard);
  26. Session.set('currentCard', null);
  27. BlazeLayout.render('defaultLayout', { content: 'board' });
  28. }
  29. });
  30. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  31. name: 'card',
  32. action: function(params) {
  33. EscapeActions.executeUpTo('popup-close');
  34. Session.set('currentBoard', params.boardId);
  35. Session.set('currentCard', params.cardId);
  36. BlazeLayout.render('defaultLayout', { content: 'board' });
  37. }
  38. });
  39. FlowRouter.route('/shortcuts', {
  40. name: 'shortcuts',
  41. action: function(params) {
  42. const shortcutsTemplate = 'keyboardShortcuts';
  43. EscapeActions.executeUpTo('popup-close');
  44. if (previousPath) {
  45. Modal.open(shortcutsTemplate, {
  46. onCloseGoTo: previousPath
  47. });
  48. } else {
  49. // XXX There is currently no way to escape this page on Sandstorm
  50. BlazeLayout.render('defaultLayout', { content: shortcutsTemplate });
  51. }
  52. }
  53. });
  54. FlowRouter.notFound = {
  55. action: function() {
  56. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  57. }
  58. }
  59. // We maintain a list of redirections to ensure that we don't break old URLs
  60. // when we change our routing scheme.
  61. var redirections = {
  62. '/boards': '/',
  63. '/boards/:id/:slug': '/b/:id/:slug',
  64. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId'
  65. };
  66. _.each(redirections, function(newPath, oldPath) {
  67. FlowRouter.route(oldPath, {
  68. triggersEnter: [function(context, redirect) {
  69. redirect(FlowRouter.path(newPath, context.params));
  70. }]
  71. });
  72. });