feat(client): add `onAfterPageLoad` for router

pull/4126/head
lejunyang 1 year ago
parent 3c40e9d9a8
commit 133a7a78da

@ -29,6 +29,10 @@ export interface Router {
* updated). Return `false` to cancel the navigation. * updated). Return `false` to cancel the navigation.
*/ */
onBeforePageLoad?: (to: string) => Awaitable<void | boolean> onBeforePageLoad?: (to: string) => Awaitable<void | boolean>
/**
* Called after the page component is loaded (before the page component is updated).
*/
onAfterPageLoad?: (to: string) => Awaitable<void>
/** /**
* Called after the route changes. * Called after the route changes.
*/ */
@ -94,6 +98,8 @@ export function createRouter(
throw new Error(`Invalid route component: ${comp}`) throw new Error(`Invalid route component: ${comp}`)
} }
await router.onAfterPageLoad?.(href)
route.path = inBrowser ? pendingPath : withBase(pendingPath) route.path = inBrowser ? pendingPath : withBase(pendingPath)
route.component = markRaw(comp) route.component = markRaw(comp)
route.data = import.meta.env.PROD route.data = import.meta.env.PROD

Loading…
Cancel
Save