BrainLikeADullPencil
BrainLikeADullPencil

Reputation: 11663

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();
                }

            });

Upvotes: 7

Views: 7190

Answers (1)

McGarnagle
McGarnagle

Reputation: 102753

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.

Upvotes: 9

Related Questions