47

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

Uncaught Error: No route matched the URL '...'

カスタム 404 ページを表示しますか?


注: この質問は以前に尋ねられ、数か月前に回答されましたが、もう機能しません。

4

5 に答える 5

6

ルーターの最後にキャッチオールルートを追加してみてください。

App.Router.map(function() {
  this.resource('post', ...);
  this.resource('user', ...);
  this.route('catchAll', { path: '/*' });
});

App.CatchAllRoute = ...
于 2013-02-17T17:42:31.593 に答える
0

解決策 1

404 コンテンツを表示するには:

App.Router.reopen({
        handleURL: function (url) {
            try {
                return this._super(url);
            } catch (error) {
                if (error.message.match(/No route matched the URL/)) {
                    return this._super('/404');
                }
            }
        }
    });

URL も 404 に変更する場合:

App.Router.reopen({
        location: locationImplementation,
        handleURL: function (url) {
            try {
                return this._super(url);
            } catch (error) {
                if (error.message.match(/No route matched the URL/)) {
                    this.transitionTo('404');
                    return this._super('/404');
                }
            }
        }
    });

ここで何が起こったかを理解するには、ember rc2 の行22636参照してください。

解決策 2

現在の URL を解析し、次を使用してルートまたはリソースが存在するかどうかを確認しますApp.Router.router.recognizer.hasRoute('route.path.goes.here');

于 2013-04-07T04:46:57.600 に答える