open-consul/ui/packages/consul-ui/app/helpers/is-href.js
John Cowen 7c36d749f5
ui: Add Route component / routlet service (#9813)
* Add Routlet service and Route Component

* Add ember-assign-helper (already an indirect dependency)

* Use EventListeners for is-href instead of observing

* Don't include :active in '-intent' styles
2021-03-08 12:15:54 +00:00

32 lines
935 B
JavaScript

import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class IsHrefHelper extends Helper {
@service('router') router;
init() {
super.init(...arguments);
this.router.on('routeWillChange', this.routeWillChange);
}
compute([targetRouteName, ...rest]) {
if (this.router.currentRouteName.startsWith('nspace.') && targetRouteName.startsWith('dc.')) {
targetRouteName = `nspace.${targetRouteName}`;
}
if (typeof this.next !== 'undefined' && this.next !== 'loading') {
return this.next.startsWith(targetRouteName);
}
return this.router.isActive(...[targetRouteName, ...rest]);
}
@action
routeWillChange(transition) {
this.next = transition.to.name.replace('.index', '');
this.recompute();
}
willDestroy() {
this.router.off('routeWillChange', this.routeWillChange);
}
}