router.js 2.2 KB

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