這裏是我的路由器:爲什麼骨幹不調用簡單的路由[及其相應的功能]?
var MyRouter = Backbone.Router.extend({
initialize: function(){
Backbone.history.start({ pushState:true });
},
routes: {
'hello' : 'sayHello'
},
sayHello: function(){
alert('Saying hello');
}
});
注意,我用{ pushState:true }
提供的網址沒有哈希代碼。
我還使用一個Node.js的服務器來處理路線:
var express = require('express');
var app = express();
app.use(express.static(__dirname));
app.listen(3010);
當我瀏覽到http://localhost:3010#hello
我的瀏覽器它更改爲http://localhost:3010/hello
的路線,但它工作正常。但是,當我親自導航到http://localhost:3010/hello
時,出現Cannot GET /hello
錯誤。
這可能有一個簡單的答案,但任何人都可以闡明我可能做錯了什麼?
在此先感謝。
當你調用URL以''#它會嘗試加載骨幹定義的路由。但直接調用它像'http:// localhost:3010/hello'正在調用你沒有定義的快速路由(即使pushstate爲true,你需要用#調用你的骨幹路由) – Sami 2014-09-01 07:27:40