feat(client): add `onAfterPageLoad` hook in router (#4126)

pull/4177/head
LJY 2 months ago committed by GitHub
parent 77beb4476e
commit 315c220049
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -107,6 +107,10 @@ interface Router {
* updated). Return `false` to cancel the navigation.
*/
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.
*/

@ -102,6 +102,10 @@ interface Router {
* 在页面组件加载前history 状态更新后)调用。返回 `false` 表示取消导航
*/
onBeforePageLoad?: (to: string) => Awaitable<void | boolean>
/**
* 在页面组件加载后(页面组件实际更新前)调用
*/
onAfterPageLoad?: (to: string) => Awaitable<void>
/**
* 在路由更改后调用
*/

@ -29,6 +29,10 @@ export interface Router {
* updated). Return `false` to cancel the navigation.
*/
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.
*/
@ -94,6 +98,8 @@ export function createRouter(
throw new Error(`Invalid route component: ${comp}`)
}
await router.onAfterPageLoad?.(href)
route.path = inBrowser ? pendingPath : withBase(pendingPath)
route.component = markRaw(comp)
route.data = import.meta.env.PROD

Loading…
Cancel
Save