2013-04-21 75 views
2

我使用Sammy.js加載了一個模板名稱,但是如果找不到該文件,我想將用戶重定向到另一個頁面。基本上,我有:如何使用Sammy.Template檢測和處理404錯誤?

this.use(Sammy.Template, 'tpl'); 

this.get('#/:page', function() { 

    // render a template 
    // this.load() 

    this.render('templates/' + this.params['page'] + '.tpl').swap(); 
}); 

我該如何處理404錯誤?

回答

1

既然你可以使用負載傳球選擇,我會做(我的頭頂有可能是語法錯誤,但邏輯是存在的。):

this.load('templates/' + this.params['page'] + '.tpl', {error: function(response) { ... handle error }).interpolate(null, location).swap(); 

執行404檢查錯誤功能。