router.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // XXX Switch to Flow-Router?
  2. var previousRoute;
  3. Router.configure({
  4. loadingTemplate: 'spinner',
  5. notFoundTemplate: 'notfound',
  6. layoutTemplate: 'defaultLayout',
  7. onBeforeAction: function() {
  8. var options = this.route.options;
  9. var loggedIn = Tracker.nonreactive(function() {
  10. return !! Meteor.userId();
  11. });
  12. // Redirect logged in users to Boards view when they try to open Login or
  13. // signup views.
  14. if (loggedIn && options.redirectLoggedInUsers) {
  15. return this.redirect('Boards');
  16. }
  17. // Authenticated
  18. if (! loggedIn && options.authenticated) {
  19. return this.redirect('atSignIn');
  20. }
  21. // We want to execute our EscapeActions.executeUpTo method any time the
  22. // route is changed, but not if the stays the same but only the parameters
  23. // change (eg when a user is navigation from a card A to a card B). Iron-
  24. // Router onBeforeAction is a reactive context (which is a bad desig choice
  25. // as explained in
  26. // https://github.com/meteorhacks/flow-router#routercurrent-is-evil) so we
  27. // need to use Tracker.nonreactive
  28. Tracker.nonreactive(function() {
  29. if (! options.noEscapeActions &&
  30. ! (previousRoute && previousRoute.options.noEscapeActions))
  31. EscapeActions.executeAll();
  32. });
  33. previousRoute = this.route;
  34. this.next();
  35. }
  36. });