Backbone.js Series Tutorial Eight: Backbone.history

Source: Internet
Author: User
Tags define object hash reference string root directory

The

Backbone.router function is to manage routing. Backbone.history is part of a route that listens for and responds to URL changes, including updates to the browser's history. The Backbone.history () constructor is instantiated by the backbone library itself, and an instance of history () is a reference to backbone.history. This Backbone.history object has a method named Start (). Call this method to notify the backbone to start listening for routing and managing browser history. The method has an option object that provides the following options and values.

 
  
  
  1. Backbone.history.st Art ({
  2.  
  3. /*boolean, default is False, true means to use pushstate if available, return hash path */
  4. Li class= "L3" >pushstate:true,
  5.  
  6. /*boolean, the default is true, A value of false means that if pushstate is true, it means that the browser does not support Pushstate, and then
  7. hashchange:false,
  8.  
  9. /* string defaults to ', backbone assume your service Start from the root path (i.e./).
  10. root: ",
  11.  
  12. /*boolean, the default is False, and a value of true means that the default route is not run (that is, ' ')。 */
  13. silent:true
  14.  

You may have never created a history () instance, but note that you will often need to invoke Backbone.history.start () to begin listening for hashchange events and calling callback functions.

Tips:

    1. Since making a hash path work in IE depends on the inline framework, it is best to call start after the DOM is ready.
    2. When start () is invoked the first time, the initialization route is run. When the. Start () is invoked, the initialization route is the current URL, which in turn invokes the route with the attribute name of the blank string associated with it.
    3. You do not need to define all the routes before calling start (). If you do not use initialization routing, on the Backbone.router () instance, you can define additional routes by calling the route () method after calling the start () method.
    4. The route does not start with a backbone.router () instance, but from the Backbone.history () instance. Keep in mind that routing objects can define routes and provide a navigate () method. But in order for the route to start loading each Web page into the browser, you need to call Backbone.history.start ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.