Skip to content

Instantly share code, notes, and snippets.

@SachaG
Created September 5, 2012 02:27
Show Gist options
  • Save SachaG/3629367 to your computer and use it in GitHub Desktop.
Save SachaG/3629367 to your computer and use it in GitHub Desktop.
if (Meteor.is_client) {
SimpleRouter = FilteredRouter.extend({
initialize: function() {
FilteredRouter.prototype.initialize.call(this);
this.filter(this.require_login, {only: ['submit']});
},
require_login: function(page) {
console.log(Meteor.user());
if (Meteor.user()) {
return page;
} else {
return 'signin';
}
},
routes: {
'': 'top',
'test':'test',
'signin':'signin',
'signup':'signup',
'submit':'submit',
'posts/:id':'post',
'comments/:id':'comment'
},
top: function() { console.log("top"); this.goto('top'); },
test: function() {console.log("test"); this.goto('test'); },
signup: function() {console.log("signup"); this.goto('signup'); },
signin: function() {console.log("signin"); this.goto('signin'); },
submit: function() {console.log("submit"); this.goto('submit'); },
post: function(id) {
Session.set('selected_post', Posts.findOne({_id:id}));
this.goto('post');
},
comment: function(id) {
Session.set('selected_comment', Comments.findOne({_id:id}));
this.goto('single_comment');
},
});
var Router = new SimpleRouter();
Meteor.startup(function() {
Backbone.history.start({pushState: true});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment