The main route is not called

I have a working application using Backbone 0.5.3 that no longer works using the 0.9.2 backbone.

I found that Router.navigate () for some reason does not call my route.

Here is my router:

var Router = Backbone.Router.extend({
    routes: {
      '/mypage': 'mypage', 
    },

    mypage: function() { 
      // show page ...
   }
});

Manual route calling also works just as well:

Router.mypage()

I also tried to rewrite the base .navigate method to debug my application ...

var Router = Backbone.Router.extend({
    routes: {
      '/mypage': 'mypage', 
    },

    navigate: function(fragment, options) {
      console.log("navigate called");
      Backbone.history.navigate(fragment, options);
    },

    mypage: function() { 
      // show page ...
   }
});

... it seems .navigate is being invoked, but ...

Backbone.history.navigate(fragment, options);

... just doesn't call the route.

I am using PushState, here is my initial call:

Backbone.history.start({ 
  root: '/',
  pushState: true,
  silent: true
});

Already tried this without root and silent options - without success.

Again: this works using Backbone 0.5.3.

Thanks to everyone who left an answer!

Achim

+5
source share
3 answers

:

Backbone.Router.extend(properties, [classProperties])

. [...] , :

, routes, :

routes: {
  'mypage': 'mypage', 
},
+2

, :

Router.navigate("/mypath", {trigger: true})

+3

You must create an instance of Router.

var router = new Router();
router.navigate(...);
0
source

All Articles