Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/web-runtime/src/router/setupRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ 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) {
return
}

const event = new CustomEvent('pathchange', {
detail: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
detail: {
details: {

why not plural form?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
})
}