add callback for leaving a page
This commit is contained in:
parent
42e0ff64d3
commit
e3e9f84641
1 changed files with 15 additions and 2 deletions
17
src/main.vue
17
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)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue