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; } });