feat: common changes for site protection (#3878)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user