Subscribe via RSS Feed

Backbone.js Router in Client Side Javascript MVC – with Java based Web Project – Part 2

April 28, 2013 3 Comments


This article is extension of Backbone.js based Application with Java based web project.

The project code can be downloaded here.

In Backbone.js Javascript MVC Frameworks, router are used to navigate web site URL’s by using hash tags(#).

All routers in Backbone.js contain route and function to map to that route. In our case, the route refers to -

// Router
var AppRouter = Backbone.Router.extend({

	initialize:function () {
        // Function is called at the time of initialization of Router.
    },

    routes:{
        "wines/new":"newWine", // a router mapping to a particular function newWine
        // Other code snippets // Other route paths...
    },

    list:function () {
        // Code to fetch the value from database using the REST based web service.
        $('#sidebar').html(this.wineListView.render().el); // Rendering a html fragment - template by Backbone View.
    },

    // Other code snippets....
    newWine:function () {
        // mapped function from route. 
        // New Model initialisation and html template rendering code to be here.
    }
});

var app = new AppRouter(); // Backbone router initialisation
Backbone.history.start(); //  Start Backbone history to capture navigation pattern in browser for later use.

More Resources :

1> What is a router?

Other Resources you may have interest :

1> Developing Java web applications with Backbone.js

2> Backbone.js in Client Side Javascript MVC – with Java based Web Project

3> Backbone.js View in Client Side Javascript MVC – with Java based Web Project – Part 3

Enter your email address:

Delivered by FeedBurner

Sign Up to read the rest of the content

Email will be used only for updates of our site

No Thanks