Last active
December 15, 2015 11:29
-
-
Save jayhjkwon/5252910 to your computer and use it in GitHub Desktop.
Backbone History API Usage
This file contains hidden or 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
<a href=''>Home</a> | |
<a href='about'>About</a> |
This file contains hidden or 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
$(function(){ | |
var app = new Backbone.Marionette.Application(); | |
app.addRegions({main : '#main'}); | |
var AppRouter = Backbone.Router.extend({ | |
initialize : function(){ | |
$('a').click(function(e){ | |
e.preventDefault(); | |
var href = $(this).attr('href'); | |
Backbone.history.navigate(href, true); | |
}); | |
}, | |
routes : { | |
'' : 'home', | |
'about' : 'about' | |
}, | |
home : function(){ | |
var homeView = new HomeView(); | |
app.main.show(homeView); | |
}, | |
about : function(){ | |
var personModel = new PersonModel({ | |
firstName : 'test', | |
addresses : new AddressesModel([ | |
new AddressModel({city : 'seoul'}), | |
new AddressModel({city : 'pusan'}), | |
new AddressModel({city : 'incheon'}) | |
]) | |
}); | |
var aboutView = new AboutView({model : personModel}); | |
app.main.show(aboutView); | |
} | |
}); | |
new AppRouter(); | |
Backbone.history.start({pushState : true}); | |
}); |
2222222
test
test
0000testtest
testtest
testtest
1
2
hi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test