Google News
logo
Backbone - Interview Questions
What is the use of Backbone.js router?
Backbone.js routers are used to route the application's URL to some particular actions and events. At least one route must be present for every defined router. It also defines the URL representation of the application's object when web applications provide linkable, bookmarkable, and sharable URL.
 
<script type="text/javascript">    
        var RouteMenu = Backbone.View.extend({    
           el: '#routemenu',  //'el' defines which element to be used as the view reference    
           events: {    
              'click a' : 'onClick'    
           },    
           onClick: function( e ) {    
              router.navigate('/');    
           }    
       });    
       var Router = Backbone.Router.extend({    
          routes: {    
             'route/:id' : 'defaultRoute'    
          },    
       });    
       var routemenu = new RouteMenu();    
       Backbone.history.start();    
</script>

 

Advertisement