Last active
December 21, 2015 01:09
-
-
Save mojaray2k/6225467 to your computer and use it in GitHub Desktop.
Creating Simple Backbone Js Routers
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
//The name of this file is backbone-routes.js | |
var AppRouter = Backbone.Router.extend({ | |
routes: { | |
"": "list", | |
"menu-items/new": "itemForm", | |
"menu-items/:item": "itemDetails" | |
}, | |
list: function () { | |
$('#app').html('List screen'); | |
}, | |
itemDetails: function (item) { | |
$('#app').html('Menu item: ' + item); | |
}, | |
itemForm: function () { | |
$('#app').html('New item form'); | |
} | |
}); | |
var app = new AppRouter(); | |
$(function() { | |
Backbone.history.start(); | |
}); |
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
<html> | |
<head> | |
<title> | |
Off the backbone | |
</title> | |
<script type="text/javascript" src="js/lib/jquery-1.9.1.min.js"> | |
</script> | |
<script type="text/javascript" src="js/lib/underscore-min.js"> | |
</script> | |
<script type="text/javascript" src="js/lib/backbone-min.js"> | |
</script> | |
<script type="text/javascript" src="js/lib/bootstrap.min.js"> | |
</script> | |
<script type="text/javascript" src="js/app.js"> | |
</script> | |
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" /> | |
<link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.min.css" /> | |
</head> | |
<body> | |
<div class="container"> | |
<h1> | |
Off the backbone | |
</h1> | |
<ul class="nav nav-pills"> | |
<li> | |
<a href="#">Food</a> | |
</li> | |
<li> | |
<a href="#/menu-items/new">Add Item</a> | |
</li> | |
<li> | |
<a href="#/menu-items/garden-salad">Garden Salad</a> | |
</li> | |
</ul> | |
</div> | |
<div class="container" id="app"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment