Emberjs-routing-rcvr-rjct
提供:Dev Guides
EmberJS-拒否から回復するルーター
約束の拒否はモデルフック内にキャッシュできます。これは、トランジションを停止させないフルフィルに変換できます。
構文
Ember.Route.extend ({
model() {
//return the recovery message
}
});
例
以下の例は、モデルがプロミスを拒否した場合に移行が中止される方法を示しています。 新しいルートを作成し、_promisereject_という名前を付け、_router.js_ファイルを開いてURLマッピングを定義します-
import Ember from 'ember';
//Access to Ember.js library as variable Ember
import config from './config/environment';
//It provides access to app's configuration data as variable config
//The const declares read only variable
const Router = Ember.Router.extend ({
location: config.locationType,
rootURL: config.rootURL
});
//Defines URL mappings that takes parameter as an object to create the routes
Router.map(function() {
this.route('recoveryrejection');
});
//It specifies Router variable available to other parts of the app
export default Router;
次のコードで_app/templates/_の下に作成された_application.hbs_ファイルを開きます-
<h2>Recovering from Rejection</h2>
{{#link-to 'recoveryrejection'}}Click Here{{/link-to}}
上記のリンクをクリックすると、recoveryrejection templateページが開きます。 _recoveryrejection.hbs_ファイルには次のコードが含まれています-
{{model.msg}}
{{outlet}}
今、次のコードで_app/routes/_の下に作成された_recoveryrejection.js_ファイルを開きます-
import Ember from 'ember';
import RSVP from 'rsvp';
export default Ember.Route.extend ({
model() {
//returning recovery message
return {
msg: "Recovered from rejected promise"
};
}
});
出力
エンバーサーバーを実行すると、次の出力が表示されます-
あなたがリンクをクリックすると、約束が拒否され、移行を続行するための回復メッセージが表示されます-