2

Sammy.js でルートからテンプレート名を取得してテンプレートを読み込みますが、ファイルが見つからない場合、ユーザーを別のページにリダイレクトしたいと考えています。基本的に、私は持っています:

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

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

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

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

404 エラーを処理するにはどうすればよいですか?

4

1 に答える 1

1

オプションを渡して load を使用できるので、私はそうします (頭のてっぺん。構文エラーがあるかもしれませんが、ロジックはそこにあります)。

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

エラー関数で 404 チェックを実行します。

于 2013-05-10T17:41:43.403 に答える