Backbone.js 为什么主干路由需要默认路由
我使用backbone.js@创建了一个测试用例: 路线定义为Backbone.js 为什么主干路由需要默认路由,backbone.js,router,Backbone.js,Router,我使用backbone.js@创建了一个测试用例: 路线定义为 var AppRouter = Backbone.Router.extend({ routes: { "/posts/:id" : "getPost", "/download/*path": "downloadFile", "*actions" : "defaultRoute" }, getPost: fun
var AppRouter = Backbone.Router.extend({
routes: {
"/posts/:id" : "getPost",
"/download/*path": "downloadFile",
"*actions" : "defaultRoute"
},
getPost: function(id) {
alert(id);
},
defaultRoute : function(actions){
alert(actions);
},
downloadFile: function( path ){
alert(path); // user/images/hey.gif
},
loadView: function( route, action ){
alert(route + "_" + action); // dashboard_graph
}
});
var app_router = new AppRouter;
Backbone.history.start();
当我改变函数时
defaultRoute : function(actions){
alert(actions);
},
到
所有其他路由都无法工作,这意味着不会弹出对话框
但当重新更改代码时,一切都正常
这真的很奇怪,让我很困惑。
SOS…正如您所知,默认路由是唯一可以触发的路由。如果你想让另外两条路线开火,你必须去掉前面的斜线
routes: {
"posts/:id" : "getPost",
"download/*path": "downloadFile",
"*actions" : "defaultRoute"
}
正如您所知,代码
defaultRoute
是唯一触发的路由。如果你想让另外两条路线开火,你必须去掉前面的斜线
routes: {
"posts/:id" : "getPost",
"download/*path": "downloadFile",
"*actions" : "defaultRoute"
}