Nothing
Nothing

Reputation: 2642

Router in backbone doesnot work

I'm sure that jquery, underscore and backbone in my main.js are working with require.js. Here my router :

define([
 'jquery',
 'underscore',
 'backbone',
 'views/CartList'
], function($, _, Backbone,CartList){
var AppRouter = Backbone.Router.extend({
    routes: {
        "showCart" : "cartlist"
    }
});
// Initiate the router
var initialize = function(){
    var app_router = new AppRouter;
    app_router.on('cartlist', function(){
        alert(1);
    });
    Backbone.history.start();
};
return {
    initialize: initialize
};
});

Here app.js :

define(["jquery", "backbone", "router"], function($, Backbone, Router) {
  var initialize = function(){
    Router.initialize();
  }
  return {
    initialize: initialize
  };
});

When I browse www.mysite.com/#showCart, It didnot show the alert.

Any help would be appreciated.

Upvotes: 0

Views: 78

Answers (1)

Vitalii Petrychuk
Vitalii Petrychuk

Reputation: 14255

Try to add route: prefix

app_router.on('route:cartlist', function () {
  alert(1);
});

Upvotes: 2

Related Questions