From fcefcb32ea2ff4f7785a786670f8aca6c601a0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Cant=C3=BA=20G=C3=B3mez?= Date: Wed, 9 Oct 2024 00:23:56 +0100 Subject: [PATCH] Update href-to.js --- addon/helpers/href-to.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/addon/helpers/href-to.js b/addon/helpers/href-to.js index c7d52e2..4733f8b 100644 --- a/addon/helpers/href-to.js +++ b/addon/helpers/href-to.js @@ -1,5 +1,6 @@ -import Helper from "@ember/component/helper"; -import { getOwner } from "@ember/application"; +import Helper from '@ember/component/helper'; +import { getOwner } from '@ember/application'; +import { action } from '@ember/object'; export function hrefTo(routing, params) { return routing.generateURL(...getParamsForGenerateURL(params)); @@ -28,11 +29,24 @@ export default class HrefToHelper extends Helper { return getOwner(this).lookup("service:router"); } + @action + _recompute() { + this.recompute(); + } + init() { super.init(); - if (this.router && this.router.on) { // skip if the router service is mocked - this.router.on("routeDidChange", this.recompute.bind(this)); + if (this.router && this.router.on) { + // skip if the router service is mocked + this.router.on("routeDidChange", this._recompute); + } + } + + willDestroy() { + super.willDestroy(); + if (this.router && this.router.on) { + this.router.off("routeDidChange", this._recompute); } }