fix supervisor ingress routing (#16474)

This commit is contained in:
Bram Kragten 2023-05-10 16:03:19 +02:00 committed by GitHub
parent 689d123890
commit d46201ebd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { HassioPanelInfo } from "../../src/data/hassio/supervisor"; import { HassioPanelInfo } from "../../src/data/hassio/supervisor";
import { Supervisor } from "../../src/data/supervisor/supervisor"; import { Supervisor } from "../../src/data/supervisor/supervisor";
import { import {
@ -22,9 +23,15 @@ class HassioRouter extends HassRouterPage {
protected routerOptions: RouterOptions = { protected routerOptions: RouterOptions = {
// Hass.io has a page with tabs, so we route all non-matching routes to it. // Hass.io has a page with tabs, so we route all non-matching routes to it.
defaultPage: "dashboard", defaultPage: "dashboard",
beforeRender: (page: string) => beforeRender: (page: string) => {
page === "snapshots" ? "backups" : undefined, if (page === "snapshots") {
initialLoad: () => this._redirectIngress(), return "backups";
}
if (page === "dashboard" && this.panel.config?.ingress) {
return "ingress";
}
return undefined;
},
showLoading: true, showLoading: true,
routes: { routes: {
dashboard: { dashboard: {
@ -55,32 +62,28 @@ class HassioRouter extends HassRouterPage {
protected updatePageEl(el) { protected updatePageEl(el) {
// the tabs page does its own routing so needs full route. // the tabs page does its own routing so needs full route.
const hassioPanel = el.nodeName === "HASSIO-PANEL"; const hassioPanel = el.localName === "hassio-panel";
const route = hassioPanel ? this.route : this.routeTail; const ingressPanel = el.localName === "hassio-ingress-view";
const route = hassioPanel
if (hassioPanel && this.panel.config?.ingress) { ? this.route
this._redirectIngress(); : ingressPanel && this.panel.config?.ingress
return; ? this._ingressRoute(this.panel.config?.ingress)
} : this.routeTail;
el.hass = this.hass; el.hass = this.hass;
el.narrow = this.narrow; el.narrow = this.narrow;
el.route = route; el.route = route;
el.supervisor = this.supervisor; el.supervisor = this.supervisor;
if (el.localName === "hassio-ingress-view") { if (ingressPanel) {
el.ingressPanel = this.panel.config && this.panel.config.ingress; el.ingressPanel = Boolean(this.panel.config?.ingress);
} }
} }
private async _redirectIngress() { private _ingressRoute = memoizeOne((ingress: string) => ({
if (this.panel.config && this.panel.config.ingress) { prefix: "/hassio/ingress",
this.route = { path: `/${ingress}`,
prefix: "/hassio", }));
path: `/ingress/${this.panel.config.ingress}`,
};
}
}
} }
declare global { declare global {