El enrutador backbone.js no responde a los fragmentos de URL
Frecuentes
Visto 593 veces
1
Tengo un enrutador simple definido e instanciado.
Problema: Cuando voy a la url http://localhost/backbone1/#photos/5
, espero ver una salida de console.log()
en la consola de javascript, pero no aparece nada. ¿Me perdí de algo?
Código JS
var GalleryRouter = Backbone.Router.extend({
routes: {
"about": "showAbout",
"photos/:id": "getPhoto",
"search/:query": "searchPhotos",
"search/:query/p:page": "searchPhotos",
"photos/:id/download/*imagePath": "downloadPhoto",
"*other": "defaultRoute"
},
showAbout: function() {
},
getPhoto: function(id) {
console.log('You are trying to reach photo ' + id);
},
searchPhotos: function(query, page) {
console.log('Page number: ' + page + ' of the results for ' + query);
},
downloadPhoto: function(id, imagePath) {
},
defaultRoute: function(other) {
console.log("Invalid. You attempted to reach: " + other);
}
});
var myGalleryRouter = new GalleryRouter();
2 Respuestas
1
Te falta un método de inicialización
var initialize = function () {
var myGalleryRouter = new GalleryRouter();
Backbone.history.start();
};
return {
initialize: initialize
};
Respondido el 12 de junio de 12 a las 17:06
0
El enrutador comienza a escuchar los cambios de hash de URL después de llamar Backbone.history.start()
. Por lo general, querrá cargar datos esenciales e inicializar vistas globales primero, luego iniciar el enrutador.
Respondido el 12 de junio de 12 a las 20:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript jquery backbone.js or haz tu propia pregunta.