我定义并实例化了一个简单的路由器。
问题:当我转到 urlhttp://localhost/backbone1/#photos/5
时,我希望在 javascript 控制台中看到输出console.log()
,但没有显示任何内容。我错过了什么吗?
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();