feat: common changes for site protection (#3878)

This commit is contained in:
Akash K
2024-03-07 23:43:20 +05:30
committed by GitHub
parent 439cd82c88
commit 6d66d12a9e
4 changed files with 16 additions and 4 deletions

View File

@@ -34,7 +34,7 @@ export type HoppModule = {
to: RouteLocationNormalized,
from: RouteLocationNormalized,
router: Router
) => void
) => void | Promise<void>
/**
* Called by the router to tell all the modules that a route navigation has completed

View File

@@ -47,15 +47,21 @@ export default <HoppModule>{
routes,
})
router.beforeEach((to, from) => {
router.beforeEach(async (to, from) => {
_isLoadingInitialRoute.value = isInitialRoute(from)
const onBeforeRouteChangePromises: Promise<any>[] = []
HOPP_MODULES.forEach((mod) => {
mod.onBeforeRouteChange?.(to, from, router)
const res = mod.onBeforeRouteChange?.(to, from, router)
if (res) onBeforeRouteChangePromises.push(res)
})
platform.addedHoppModules?.forEach((mod) => {
mod.onBeforeRouteChange?.(to, from, router)
const res = mod.onBeforeRouteChange?.(to, from, router)
if (res) onBeforeRouteChangePromises.push(res)
})
await Promise.all(onBeforeRouteChangePromises)
})
// Instead of this a better architecture is for the router