1

I tried the below code that does not work. Also i searched via google but find nothing. Backbone's official documentation does not have an entry about loadUrl.

app_router.on('route:page', function(id, name) {
    ...
});

app_router.on('route:file', function(id, name) {
      // first open the page
      Backbone.history.loadUrl("page", function() {
        // and open the file manager after page is loaded
      });
});
fozuse
  • 754
  • 2
  • 11
  • 29

1 Answers1

1

You cannot pass callback in loadUrl.

From 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.

And function definition

loadUrl: function(fragment)

Instead use

 router.on("route", function() {
   ...
 });

To answer your edited question, you can do something like

 app_router.on('route:file', function(id, name) {
    // first open the page
    if(Backbone.history.loadUrl("page")){
       // and open the file manager after page is loaded
    });
 });
Sami
  • 3,926
  • 1
  • 29
  • 42
  • I just updated the question. Please look again. I have to run loadUrl in another route. Before loading the file manager, i have to be shore the page is loaded. Otherwise my code will be broken. – fozuse Feb 23 '15 at 17:21
  • Maybe i can merge two route, i don't know. – fozuse Feb 23 '15 at 17:36