Skip to content

Instantly share code, notes, and snippets.

@mitchlloyd
Forked from mguterl/about.hbs
Last active October 2, 2015 17:26
Show Gist options
  • Save mitchlloyd/9def667b38a8da9558d4 to your computer and use it in GitHub Desktop.
Save mitchlloyd/9def667b38a8da9558d4 to your computer and use it in GitHub Desktop.
{{bd-back-button}}
<i class="bd-icon bd-icon--arrow-left"></i>
import Ember from 'ember';
const { inject } = Ember;
export default Ember.Component.extend({
tagName: 'a',
classNames: ['button button--return'],
attributeBindings: ['href', 'title'],
history: inject.service(),
click: function() {
this.get('history').goBack();
}
});
// in instance-initializers/boot-history.js
//
// Not sure if this would work, but it would be interesting to see if
// this would let the history service capture the first willTransition
// event.
export function initialize(application) {
application.container.lookup('service:history');
}
export default {
name: 'boot-history',
initialize: initialize
};
import Ember from 'ember';
const { inject } = Ember;
export default Ember.Service.extend({
routing: inject.service('-routing'),
// whatever stuff is already here
init() {
this._super(...arguments);
this.get('routing.router').on('willTransition', (t) => this.capture(t));
},
goBack() {
let previousTransition = this.get('previous');
if (previousTransition) {
this.capture(previousTransition);
previousTransition.retry();
} else {
this.get('routing').transitionTo('home');
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment