diff --git a/src/panels/config/integrations/ha-config-integrations-dashboard.ts b/src/panels/config/integrations/ha-config-integrations-dashboard.ts index 5c23131ceb..b4036dc9b9 100644 --- a/src/panels/config/integrations/ha-config-integrations-dashboard.ts +++ b/src/panels/config/integrations/ha-config-integrations-dashboard.ts @@ -336,9 +336,7 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin( super.firstUpdated(changed); this._fetchManifests(); this._fetchEntitySources(); - if (this.route.path === "/add") { - this._handleAdd(); - } + this._handleRouteChanged(); this._scanUSBDevices(); this._scanImprovDevices(); @@ -355,6 +353,9 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin( protected updated(changed: PropertyValues) { super.updated(changed); + if (changed.has("route")) { + this._handleRouteChanged(); + } if ( (this._searchParms.has("config_entry") || this._searchParms.has("domain")) && @@ -813,10 +814,13 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin( } } - private async _handleAdd() { + private async _handleRouteChanged() { + if (this.route?.path !== "/add") { + return; + } const brand = extractSearchParam("brand"); const domain = extractSearchParam("domain"); - navigate("/config/integrations", { replace: true }); + navigate("/config/integrations/dashboard/", { replace: true }); if (brand) { showAddIntegrationDialog(this, { diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index 205a5a41e4..e1b2a2467c 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -655,8 +655,13 @@ class HUIRoot extends LitElement { this.toggleAttribute("scrolled", window.scrollY !== 0); }; + private _locationChanged = () => { + this._handleUrlChanged(); + }; + private _handlePopState = () => { this._restoreScroll = true; + this._handleUrlChanged(); }; private _isVisible = (view: LovelaceViewConfig) => @@ -678,6 +683,34 @@ class HUIRoot extends LitElement { protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); + window.addEventListener("scroll", this._handleWindowScroll, { + passive: true, + }); + this._handleUrlChanged(); + } + + public connectedCallback(): void { + super.connectedCallback(); + window.addEventListener("scroll", this._handleWindowScroll, { + passive: true, + }); + window.addEventListener("popstate", this._handlePopState); + window.addEventListener("location-changed", this._locationChanged); + // Disable history scroll restoration because it is managed manually here + window.history.scrollRestoration = "manual"; + } + + public disconnectedCallback(): void { + super.disconnectedCallback(); + window.removeEventListener("scroll", this._handleWindowScroll); + window.removeEventListener("popstate", this._handlePopState); + window.removeEventListener("location-changed", this._locationChanged); + this.toggleAttribute("scrolled", window.scrollY !== 0); + // Re-enable history scroll restoration when leaving the page + window.history.scrollRestoration = "auto"; + } + + private _handleUrlChanged() { // Check for requested edit mode const searchParams = extractSearchParamsObject(); if (searchParams.edit === "1") { @@ -697,29 +730,6 @@ class HUIRoot extends LitElement { this._showMoreInfoDialog(entityId); }); } - - window.addEventListener("scroll", this._handleWindowScroll, { - passive: true, - }); - } - - public connectedCallback(): void { - super.connectedCallback(); - window.addEventListener("scroll", this._handleWindowScroll, { - passive: true, - }); - window.addEventListener("popstate", this._handlePopState); - // Disable history scroll restoration because it is managed manually here - window.history.scrollRestoration = "manual"; - } - - public disconnectedCallback(): void { - super.disconnectedCallback(); - window.removeEventListener("scroll", this._handleWindowScroll); - window.removeEventListener("popstate", this._handlePopState); - this.toggleAttribute("scrolled", window.scrollY !== 0); - // Re-enable history scroll restoration when leaving the page - window.history.scrollRestoration = "auto"; } protected willUpdate(changedProperties: PropertyValues): void {