エラーを処理するにはどうすればよいですか
Uncaught Error: No route matched the URL '...'
カスタム 404 ページを表示しますか?
注: この質問は以前に尋ねられ、数か月前に回答されましたが、もう機能しません。
ルーターの最後にキャッチオールルートを追加してみてください。
App.Router.map(function() {
this.resource('post', ...);
this.resource('user', ...);
this.route('catchAll', { path: '/*' });
});
App.CatchAllRoute = ...
解決策 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');