If I enable pushState in the backbone router, do I need to use return false on all links or does backbone handle this automatically? Is there any samples out there, both the html part and the script part.
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
Front-End MVC frameworks (Backbone, Angular, etc) all rely on a backend service to provide the data that, say Backbone, would then use as its model. You could have an entire MVC pattern on the backend that accepts requests and spits out some JSON for a frontend MVC framework to use.
BackboneJS is a lightweight JavaScript library that allows to develop and structure the client side applications that run in a web browser. It offers MVC framework which abstracts data into models, DOM into views and bind these two using events.
Backbone is a JavaScript MVC library and that's a key difference. In the JavaScript MVC context, a framework usually means that you need to configure your code to get things done.
This is the pattern Tim Branyen uses in his boilerplate:
initializeRouter: function () { Backbone.history.start({ pushState: true }); $(document).on('click', 'a:not([data-bypass])', function (evt) { var href = $(this).attr('href'); var protocol = this.protocol + '//'; if (href.slice(protocol.length) !== protocol) { evt.preventDefault(); app.router.navigate(href, true); } }); }
Using that, rather than individually doing preventDefault on links, you let the router handle them by default and make exceptions by having a data-bypass
attribute. In my experience it works well as a pattern. I don't know of any great examples around, but trying it out yourself should not be too hard. Backbone's beauty lies in its simplicity ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With