CodesJava

Easy learning with example program codes

Backbone.JS Router Routes()

The Backbone.JS Router Routes() method defines the URL representation of application’s objects on routers.

Syntax:

Router.Routes

Example:

<!DOCTYPE html>  
<html>
<head>  
<title>Example</title>  
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" 
type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" 
type="text/javascript"></script>  
</head>  
<body>  
<script type="text/javascript">  
var X = Backbone.Router.extend({  
routes: {  
'': 'route_1',  
'R2': 'route_2'  
},  
route_1: function(){  
document.write("Called Route 1.");  
},  
route_2: function(){  
document.write("Called Route 2.");  
},  });  
var Y = new X;     
Backbone.history.start();  
</script>  
</body>  
</html>

Output:

Called Route 1.

Explanation:
In the above example the Routes() method calls the desired route.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status