History
History like a global router , it keeps track of the history, matches the appropriate route, trigger callbacks and enables the routing in the application.
Javascript handle history object by creating pushState().But older browsers does not support pushState . BackboneJS smartly handle new and old browser.you can handle enable / diasbale pushState by pushState: true/false .
After routers is created, and all of the routes are set up properly
, Backbone.history.start() to begin monitoring change.
Syntax : Backbone.history.start([options])
Example
History like a global router , it keeps track of the history, matches the appropriate route, trigger callbacks and enables the routing in the application.
Javascript handle history object by creating pushState().But older browsers does not support pushState . BackboneJS smartly handle new and old browser.you can handle enable / diasbale pushState by pushState: true/false .
After routers is created, and all of the routes are set up properly
, Backbone.history.start() to begin monitoring change.
Syntax : Backbone.history.start([options])
Example
<!DOCTYPE
html>
<head>
<title>Router
Extend 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>
<script
type="text/javascript">
var
MyRoute = Backbone.Router.extend({
routes:
{
"Item":
"myItem"
},
myItem:
function
(myroute) {
document.write(myroute);
}
});
var
rtObj = new
MyRoute();
Backbone.history.start({
pushState: true
});
</script>
<body>
<a
href="#route1">Route1
</a><a
href="#route2">Route2
</a><a
href="#route3">Route3
</a>
</body>
No comments:
Post a Comment