Last active
January 2, 2016 08:39
-
-
Save kapv89/8277677 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// router | |
define( | |
['backbone'], | |
function (backbone) { | |
var router = new backbone.Router; | |
return { | |
route: function (uri, name, handler) { | |
router.route(uri, name, handler); | |
}, | |
navigate: function (uri, options) { | |
router.navigate(uri, options); | |
}, | |
start: function () { | |
backbone.history.start({pushState: true}); | |
} | |
}; | |
}); | |
////// site ctrl | |
define( | |
['backbone', 'underscore', 'jquery', 'router', './views/home'], | |
function (backbone, _, $, router, homeView) { | |
var activeView = null; | |
var render = function (view) { | |
activeView && activeView.off(); | |
activeView = view; | |
activeView.render(); | |
} | |
return { | |
home: function () { | |
render(homeView); | |
}, | |
about: function () { | |
}, | |
contact: function () { | |
}, | |
start: function () { | |
router.route('/home', 'home', this.home) | |
router.route('/about', 'about', this.about) | |
router.route('/contact', 'contact', this.contact) | |
} | |
} | |
}) | |
//// main | |
requirejs( | |
['site', 'router'], | |
function (site, router) { | |
site.start(); | |
router.start(); | |
router.navigate('home', {trigger: true}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment