2018-02-14 13:58:55 +08:00

29 lines
703 B
JavaScript

import Service from '@ember/service';
import { getOwner } from '@ember/application';
export default Service.extend({
states: [],
max: 16,
previous() {
return this.get('states.lastObject');
},
push(url) {
if (url) {
const me = this;
me.get('states').pushObject(url);
while (me.get('states.length') > me.get('max')) {
me.get('states').shiftObject();
}
}
},
back() {
const me = this;
const url = me.previous();
if (url) {
const router = getOwner(this).lookup('router:main');
router.transitionTo(url);
}
return url;
}
});