summaryrefslogtreecommitdiffstats
path: root/client/config/router.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/config/router.js')
-rw-r--r--client/config/router.js97
1 files changed, 55 insertions, 42 deletions
diff --git a/client/config/router.js b/client/config/router.js
index 97871e23..e251aea0 100644
--- a/client/config/router.js
+++ b/client/config/router.js
@@ -1,44 +1,57 @@
-// XXX Switch to Flow-Router?
-var previousRoute;
-
-Router.configure({
- loadingTemplate: 'spinner',
- notFoundTemplate: 'notfound',
- layoutTemplate: 'defaultLayout',
-
- onBeforeAction: function() {
- var options = this.route.options;
-
- var loggedIn = Tracker.nonreactive(function() {
- return !! Meteor.userId();
- });
-
- // Redirect logged in users to Boards view when they try to open Login or
- // signup views.
- if (loggedIn && options.redirectLoggedInUsers) {
- return this.redirect('Boards');
- }
-
- // Authenticated
- if (! loggedIn && options.authenticated) {
- return this.redirect('atSignIn');
- }
-
- // We want to execute our EscapeActions.executeUpTo method any time the
- // route is changed, but not if the stays the same but only the parameters
- // change (eg when a user is navigation from a card A to a card B). Iron-
- // Router onBeforeAction is a reactive context (which is a bad desig choice
- // as explained in
- // https://github.com/meteorhacks/flow-router#routercurrent-is-evil) so we
- // need to use Tracker.nonreactive
- Tracker.nonreactive(function() {
- if (! options.noEscapeActions &&
- ! (previousRoute && previousRoute.options.noEscapeActions))
- EscapeActions.executeAll();
- });
-
- previousRoute = this.route;
-
- this.next();
+FlowRouter.route('/', {
+ name: 'home',
+ triggersEnter: [AccountsTemplates.ensureSignedIn],
+ action: function() {
+ EscapeActions.executeAll();
+ Filter.reset();
+
+ Session.set('currentBoard', '');
+
+ BlazeLayout.render('defaultLayout', { content: 'boardList' });
+ }
+});
+
+FlowRouter.route('/b/:id/:slug', {
+ name: 'board',
+ action: function(params) {
+ EscapeActions.executeAll();
+
+ Session.set('currentBoard', params.id);
+ Session.set('currentCard', null);
+
+ BlazeLayout.render('defaultLayout', { content: 'board' });
+ }
+});
+
+FlowRouter.route('/b/:boardId/:slug/:cardId', {
+ name: 'card',
+ action: function(params) {
+ Session.set('currentBoard', params.boardId);
+ Session.set('currentCard', params.cardId);
+ EscapeActions.executeUpTo('popup');
+
+ BlazeLayout.render('defaultLayout', { content: 'board' });
+ }
+});
+
+FlowRouter.notFound = {
+ action: function() {
+ BlazeLayout.render('defaultLayout', { content: 'notFound' });
}
+}
+
+// We maintain a list of redirections to ensure that we don't break old URLs
+// when we change our routing scheme.
+var redirections = {
+ '/boards': '/',
+ '/boards/:id/:slug': '/b/:id/:slug',
+ '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId'
+};
+
+_.each(redirections, function(newPath, oldPath) {
+ FlowRouter.route(oldPath, {
+ triggersEnter: [function(context, redirect) {
+ redirect(FlowRouter.path(newPath, context.params));
+ }]
+ });
});