From e3e9f84641dcf03d38b76e06ed57cec85893dc93 Mon Sep 17 00:00:00 2001 From: Lightling Date: Tue, 9 Apr 2024 21:55:42 -0400 Subject: [PATCH] add callback for leaving a page --- src/main.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.vue b/src/main.vue index bfc2714..a101dd9 100644 --- a/src/main.vue +++ b/src/main.vue @@ -61,8 +61,10 @@ const determineGlobalStylesheets = () => { const determineScript = async () => { if (!!routeConfig.scriptUrl) { - const { init } = await import(/* @vite-ignore */ routeConfig.scriptUrl) - init() + const { callbacks } = await import(/* @vite-ignore */ routeConfig.scriptUrl) + if (!!callbacks.onPageLoaded) { + callbacks.onPageLoaded(); + } } return null @@ -93,11 +95,22 @@ const onRouteLoaded = async () => { await determineScript() } +const handlePageClosed = async (scriptUrl?: string) => { + if (!!scriptUrl) { + const { callbacks } = await import(/* @vite-ignore */ scriptUrl) + if (!!callbacks.onPageClosed) { + callbacks.onPageClosed() + } + } +} + onMounted(async () => { await refresh() determineGlobalStylesheets() router.afterEach(async (to, from) => { + const oldUrl = routeConfig.scriptUrl await refresh() + await handlePageClosed(oldUrl) }) })