diff --git a/src/common/navigate.ts b/src/common/navigate.ts index 33ee8d46d9..20d45623c9 100644 --- a/src/common/navigate.ts +++ b/src/common/navigate.ts @@ -1,5 +1,14 @@ import { fireEvent } from "./dom/fire_event"; +declare global { + // for fire event + interface HASSDomEvents { + "location-changed": { + replace: boolean; + }; + } +} + export const navigate = ( _node: any, path: string, @@ -18,5 +27,7 @@ export const navigate = ( history.pushState(null, "", path); } } - fireEvent(window, "location-changed"); + fireEvent(window, "location-changed", { + replace, + }); }; diff --git a/src/entrypoints/custom-panel.js b/src/entrypoints/custom-panel.js index ea3c84b481..1d064943ce 100644 --- a/src/entrypoints/custom-panel.js +++ b/src/entrypoints/custom-panel.js @@ -56,8 +56,11 @@ function initialize(panel, properties) { const forwardEvent = (ev) => window.parent.customPanel.fire(ev.type, ev.detail); root.addEventListener("hass-toggle-menu", forwardEvent); - window.addEventListener("location-changed", () => - window.parent.customPanel.navigate(window.location.pathname) + window.addEventListener("location-changed", (ev) => + window.parent.customPanel.navigate( + window.location.pathname, + ev.detail ? ev.detail.replace : false + ) ); setProperties(Object.assign({ panel }, properties)); document.body.appendChild(root); diff --git a/src/polymer-types.ts b/src/polymer-types.ts index ba52bf7e0d..e13e45297a 100644 --- a/src/polymer-types.ts +++ b/src/polymer-types.ts @@ -25,7 +25,6 @@ declare global { "iron-resize": undefined; "config-refresh": undefined; "ha-refresh-cloud-status": undefined; - "location-changed": undefined; "hass-notification": { message: string; };