Skip to content

Instantly share code, notes, and snippets.

@golampo
Forked from yatinranadive/controllers.application.js
Last active October 19, 2018 23:16
Show Gist options
  • Save golampo/7dbb36d876367c2eb76abce95461d4c1 to your computer and use it in GitHub Desktop.
Save golampo/7dbb36d876367c2eb76abce95461d4c1 to your computer and use it in GitHub Desktop.
Retry aborted transition
import Ember from 'ember';
export default Ember.Controller.extend({
abortedTransition: undefined,
actions: {
navigate() {
this.transitionToRoute('success');
},
retry() {
this.get('abortedTransition').retry().then(() => {
this.set('abortedTransition', undefined);
this.set('isSuccess', true);
});
}
}
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('my-route');
this.route('success');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
willTransition(transition) {
if (!this.controller.get('abortedTransition')) {
transition.abort();
this.controller.set('abortedTransition', transition);
}
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
{{#if abortedTransition}}
<button {{action "retry"}}>Retry the aborted transition</button>
{{else if isSuccess}}
{{#link-to "index"}}Start over{{/link-to}}
{{else}}
<button {{action "navigate"}}>This transition is going to abort</button>
{{/if}}
{{outlet}}
<p>You made it to the end. Congrats.</p>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment