From 3d436ac7233004a3a7e26ade98bf4d006c227589 Mon Sep 17 00:00:00 2001 From: Alexander Ackermann Date: Thu, 31 Jul 2025 00:42:22 +0200 Subject: [PATCH 1/3] feat: dispatch pathchange event for external integrations --- packages/web-runtime/src/router/setupRouter.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/web-runtime/src/router/setupRouter.ts b/packages/web-runtime/src/router/setupRouter.ts index baaae63247..78bdc3e4c2 100644 --- a/packages/web-runtime/src/router/setupRouter.ts +++ b/packages/web-runtime/src/router/setupRouter.ts @@ -2,8 +2,19 @@ import { useModals } from '@opencloud-eu/web-pkg/src' import { Router } from 'vue-router' export const setupRouterHooks = (router: Router) => { + // Automatically close all open modals before each route change router.beforeEach(() => { const modalsStore = useModals() modalsStore.removeAllModals() }) + + // Dispatch a "pathchange" event after navigation for external integrations to react to + router.afterEach((to, from) => { + if (to.path !== from.path) { + const event = new CustomEvent('pathchange', { + detail: { to, from } + }) + window.dispatchEvent(event) + } + }) } From 426cfdc139012a6888396431b0b49e20c106dfaf Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 31 Jul 2025 00:44:43 +0200 Subject: [PATCH 2/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/web-runtime/src/router/setupRouter.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/web-runtime/src/router/setupRouter.ts b/packages/web-runtime/src/router/setupRouter.ts index 78bdc3e4c2..4d164c9d64 100644 --- a/packages/web-runtime/src/router/setupRouter.ts +++ b/packages/web-runtime/src/router/setupRouter.ts @@ -10,11 +10,12 @@ export const setupRouterHooks = (router: Router) => { // Dispatch a "pathchange" event after navigation for external integrations to react to router.afterEach((to, from) => { - if (to.path !== from.path) { - const event = new CustomEvent('pathchange', { - detail: { to, from } - }) - window.dispatchEvent(event) + if (to.path === from.path) { + return } + const event = new CustomEvent('pathchange', { + detail: { to, from } + }) + window.dispatchEvent(event) }) } From 86756416839208105846ed63e24511e7ca08b50a Mon Sep 17 00:00:00 2001 From: Alexander Ackermann Date: Thu, 31 Jul 2025 00:53:29 +0200 Subject: [PATCH 3/3] expose less data --- packages/web-runtime/src/router/setupRouter.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/web-runtime/src/router/setupRouter.ts b/packages/web-runtime/src/router/setupRouter.ts index 4d164c9d64..599e1fe2bb 100644 --- a/packages/web-runtime/src/router/setupRouter.ts +++ b/packages/web-runtime/src/router/setupRouter.ts @@ -13,8 +13,12 @@ export const setupRouterHooks = (router: Router) => { if (to.path === from.path) { return } + const event = new CustomEvent('pathchange', { - detail: { to, from } + detail: { + to: { url: new URL(to.fullPath, window.location.origin).href, name: to.name }, + from: { name: from.name, url: new URL(from.fullPath, window.location.origin).href } + } }) window.dispatchEvent(event) })