Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone.history.loadURL

There's no documentation for Backbone.history.loadURL on backbone.js website http://backbonejs.org/#History-start Although I have a general idea what result it produces in some applications I've looked at, I'm not exactly sure how it works, in the sense of which url it chooses to load and how it knows to load a certain url over another. Can anyone explain?

$.ajax({
                url: "json/Backboneapp_data.json",
                dataType: 'json',
                data: {},
                async: false,
                success: function (data)
                {

                    _this._data = data;
                    _this._items = new ItemCollection(data);
                    _this._view = new MenuView({ model: _this._items });
                    _this._view.render();
                    Backbone.history.loadUrl();
                }

            });
like image 871
BrainLikeADullPencil Avatar asked Oct 20 '12 20:10

BrainLikeADullPencil


1 Answers

Notes on loadUrl from the Annotated Source:

Attempt to load the current URL fragment. If a route succeeds with a match, returns true. If no defined routes matches the fragment, returns false.

So, if the current URL fragment (or the one you pass as a parameter) is valid, then it invokes route. Note also that the function returns true if it resolved a valid route based on the fragment, otherwise false.

If it helps clarify: look down in the source, and you'll notice that loadUrl is what navigate calls if you specify the option trigger:true.

like image 155
McGarnagle Avatar answered Oct 24 '22 14:10

McGarnagle