您可以中止并重试转换。在显示确认对话框之前,您必须中止转换。确认您的对话框后,您可以重试转换并阻止您的代码再次显示您的确认对话框。所以以下应该有效(未经测试):
export default Ember.Route.extend({
// ...
showConfirmation: true,
actions: {
willTransition(transition) {
if(!this.get('showConfirmation')) {
this.set('showConfirmation', true);
return true;
}
// Abort the transition for now
transition.abort();
// Now show a confirm box with alertify.
// According to the docs, only the following
// is allowed: http://alertifyjs.com/confirm.html
alertify.confirm('Are you sure you want to navigate?', () => {
// According to the documentation of alertify,
// this code is only run when you confirm your box.
this.set('showConfirmation', false);
transition.retry();
});
}
}
}