Skip to content

Instantly share code, notes, and snippets.

@mattborn
Created April 4, 2013 15:48
Show Gist options
  • Save mattborn/5311578 to your computer and use it in GitHub Desktop.
Save mattborn/5311578 to your computer and use it in GitHub Desktop.
Recent concept of Backbone router for Redemption.
define(['jquery', 'lodash', 'backbone', 'moment'],
function($, _, Backbone) {
var Router = Backbone.Router.extend({
routes: {
'visit': 'visit',
'connect': 'connect',
'events': 'events',
'sermons': 'sermons',
'*actions': 'default'
}
});
var initialize = function() {
var router = new Router;
router.on('route:visit', function() {
console.log('visit');
});
router.on('route:connect', function() {
console.log('connect');
});
router.on('route:events', function() {
console.log('events');
});
router.on('route:sermons', function() {
console.log('sermons');
});
router.on('route:default', function(actions) {
if (actions === '') { actions = 'home'; }
console.log('Route:', actions);
});
Backbone.history.start({pushState: true});
var RedemptionView = Backbone.View.extend({
el: 'body',
events: {
'click a': 'nav'
},
nav: function(event) {
event.preventDefault();
// teardown
// fire
router.navigate($(event.target).attr('href'), true);
console.log(Backbone.history);
}
}),
redemptionView = new RedemptionView;
console.log('Redemption initialized');
};
return {
initialize: initialize
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment