2014-04-24 56 views
0

我有如下的HTML標記,其中操作是在sammyjs定義路由的路由路徑中的一個的代碼:不能夠匹配現有路由路徑和獲取404未找到

<form id="loginform" action="#/login" method="post" class="form-horizontal"> 

<!-- input & hidden elements --> 

<!-- submit button --> 

</form> 

如果上述觀點通過URL加載像「本地主機:XXX /帳號/登錄」,當我提交以上表格,sammyjs記錄錯誤,這是無法找到的路線:

[Thu Apr 24 2014 13:52:39 GMT+0100 (GMT Daylight Time)] #shell 404 Not Found get /Account/Login#/login 
Error {message: "404 Not Found get /Account/Login#/login ", stack: "Error↵ at Object.Sammy.Application.$.extend.err…/localhost:36141/Scripts/Vendor/require.js:132:23"} 
message: "404 Not Found get /Account/Login#/login " 
stack: "Error↵ at Object.Sammy.Application.$.extend.error (http://localhost:36141/Scripts/Vendor/sammy-0.7.4.js:1346:47)↵ at Object.Sammy.Application.$.extend.notFound (http://localhost:36141/Scripts/Vendor/sammy-0.7.4.js:1335:22)↵ at Object.Sammy.Application.$.extend.runRoute (http://localhost:36141/Scripts/Vendor/sammy-0.7.4.js:1179:21)↵ at Object.Sammy.Application.$.extend._checkLocation (http://localhost:36141/Scripts/Vendor/sammy-0.7.4.js:1365:25)↵ at Object.Sammy.Application.$.extend.run (http://localhost:36141/Scripts/Vendor/sammy-0.7.4.js:971:12)↵ at http://localhost:36141/Scripts/App/common.js:36:19↵ at Object.context.execCb (http://localhost:36141/Scripts/Vendor/require.js:1650:33)↵ at Object.Module.check (http://localhost:36141/Scripts/Vendor/require.js:866:51)↵ at Object.<anonymous> (http://localhost:36141/Scripts/Vendor/require.js:1113:34)↵ at http://localhost:36141/Scripts/Vendor/require.js:132:23" 
__proto__: d 

我無法理解爲什麼sammy尋找「 /帳戶/登錄#/登錄「,因爲我的表單操作設置爲」#/ login「

我也試圖改變下面的錯誤上面提到的,像「#/登錄」「/帳號/登錄#/登錄」路由路徑我的劇本,但我再次得到了同樣的錯誤如上面鏈接所述。

this.post('#/login', function (context) { 
//process 
}); 

與其他鏈接或表單標籤相同。我想要使​​用的哈希標籤後綴爲URL中的任何內容,如「/ Account/Login#{/ any_hash_tag}」。 我該怎麼做才能解決這個問題?

但是,如果視圖是通過像「localhost:xxx /」這樣的url加載的,並且沒有其他路由參數,那麼一切正常。

這將是很高興知道是否有什麼我做錯了。

乾杯

+0

您正在使用相對鏈接...如果您正在查看「www.mysite.com/pages/index.html」,並且存在與「about.html」href鏈接,您會期望在哪裏那要帶你? 'www.mysite.com/about.html'或'www.mysite.com/pages/about.html'? –

+1

@JasonP我不會在任何地方寫相關鏈接。它的sammy路由庫增加了當前的url + form的動作(「#/ login」),所以它變成了「/ Account/Login#login」。即使我無法弄清楚這一點,因爲我期望sammy路由尋找「#/ login」路徑。 –

+0

@Yoda你是__absolutely__使用相對路徑。研究URL碎片如何工作。 – rockerest

回答

0

這是怎麼URL Fragments工作。

Sammy希望路由從域名開始,後跟斜槓。
連接到#[anything]的錨定標記會將該URL片段附加到當前視圖的末尾。

你可以解決這個幾個方面:

  1. 使用薩米完全,或者根本就不使用它。我不知道爲什麼你會有像/Account/Login#/login這樣的路線,但它看起來很亂,而且看起來有兩臺路由器。這並不好玩。使用Sammy像#/account/login
  2. 使您的鏈接操作做到/#/login。這將重置基本路由到web根目錄,然後將片段追加到最後。
+0

我之前用裝載器查看#2,但當我將默認URL更改爲「/帳戶/登錄」時,我開始得到這個路徑未找到錯誤。另外,在http://sammyjs.org/docs/routes的Paths部分查看,sammy也與相關的url一起工作。 –