diff --git a/src/ui/src/components/core/root/CoreRoot.vue b/src/ui/src/components/core/root/CoreRoot.vue index e9eaee9dc..e1dc65e6a 100644 --- a/src/ui/src/components/core/root/CoreRoot.vue +++ b/src/ui/src/components/core/root/CoreRoot.vue @@ -75,7 +75,7 @@ export default { }, events: { "wf-app-open": { - desc: "Captures the first application load, capture the page key and route vars.", + desc: "Captures the first application load, including page key and route vars.", stub: wfAppOpenStub, }, "wf-hashchange": { @@ -135,12 +135,12 @@ watch(activePageId, (newPageId) => { changePageInHash(pageKey); }); -type UrlParams = { +type UrlHashParams = { pageKey?: string; routeVars: Record; }; -function getUrlParams(): UrlParams { +function getUrlHashParams(): UrlHashParams { const docHash = document.location.hash.substring(1); const hashMatchGroups = docHash.match(hashRegex)?.groups; let pageKey: string; @@ -165,7 +165,7 @@ function getUrlParams(): UrlParams { return { pageKey, routeVars }; } -function setHash(urlParams: UrlParams) { +function setHash(urlParams: UrlHashParams) { const { pageKey, routeVars } = urlParams; let hash = ""; @@ -190,35 +190,35 @@ function setHash(urlParams: UrlParams) { } function changePageInHash(targetPageKey: string) { - const urlParams = getUrlParams(); - urlParams.pageKey = targetPageKey; - setHash(urlParams); + const urlHashParams = getUrlHashParams(); + urlHashParams.pageKey = targetPageKey; + setHash(urlHashParams); } function changeRouteVarsInHash(targetRouteVars: Record) { - const parsedHash = getUrlParams(); - const routeVars = parsedHash?.routeVars ?? {}; - parsedHash.routeVars = { ...routeVars, ...targetRouteVars }; - setHash(parsedHash); + const urlHashParams = getUrlHashParams(); + const routeVars = urlHashParams?.routeVars ?? {}; + urlHashParams.routeVars = { ...routeVars, ...targetRouteVars }; + setHash(urlHashParams); } function handleHashChange() { - const urlParams = getUrlParams(); + const urlHashParams = getUrlHashParams(); const event = new CustomEvent("wf-hashchange", { detail: { - payload: urlParams, + payload: urlHashParams, }, }); rootEl.value?.dispatchEvent(event); - if (!urlParams.pageKey) return; - wf.setActivePageFromKey(urlParams.pageKey); + if (!urlHashParams.pageKey) return; + wf.setActivePageFromKey(urlHashParams.pageKey); } function handleAppOpenChange() { - const urlParams = getUrlParams(); + const urlHashParams = getUrlHashParams(); const event = new CustomEvent("wf-app-open", { detail: { - payload: urlParams, + payload: urlHashParams, }, }); rootEl.value?.dispatchEvent(event);