Routers backbones.js, problem with routes

0

I'm using the Backbone.js framework and I'm using the routers to create urls on my page.

It turns out that I think I already have it, but when I open the Chrome console it says the following:

backbone.js:7 Uncaught SyntaxError: Unexpected string

It's weird because I use the same patterns as in the examples I found.

I leave the code:

 (function(){
    var Router = Backbone.Router.extend({
      routes: {

            "boton1/:id" : "vistauno"
            "boton2/:id" : "vistados"
            "boton3/:id" : "vistatres"
    },

      vistauno: function (boton1) {
          console.log("estas intentando acceder a "+boton1);
    },
      vistados: function (boton2) {
          console.log("estas intentando acceder a "+boton2);
    },
      vistatres: function (boton3) {
          console.log("estas intentando acceder a "+boton3);
    }

  });
      var Router = new Router();
      Backbone.history.start();
  })();

The error seems to be in line 7, in "boton2/:id" : "vistados" , but I find it strange because all the examples that I have looked at do the same ..

    
asked by Cucumberita 21.06.2016 в 15:58
source

1 answer

0

As I mentioned in the comments, the problem was a simple typo . In the definition of routes it is necessary to separate each element with a , , this being the result:

(function(){
var Router = Backbone.Router.extend({
  routes: {

        "boton1/:id" : "vistauno", //<-- Necesario
        "boton2/:id" : "vistados", //<-- Necesario
        "boton3/:id" : "vistatres"
},

  vistauno: function (boton1) {
      console.log("estas intentando acceder a "+boton1);
},
  vistados: function (boton2) {
      console.log("estas intentando acceder a "+boton2);
},
  vistatres: function (boton3) {
      console.log("estas intentando acceder a "+boton3);
}
});
   var Router = new Router();
   Backbone.history.start();
})();
    
answered by 21.06.2016 / 16:33
source