Skip to content

Commit 315c220

Browse files
authored
feat(client): add onAfterPageLoad hook in router (#4126)
1 parent 77beb44 commit 315c220

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

docs/en/reference/runtime-api.md

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ interface Router {
107107
* updated). Return `false` to cancel the navigation.
108108
*/
109109
onBeforePageLoad?: (to: string) => Awaitable<void | boolean>
110+
/**
111+
* Called after the page component is loaded (before the page component is updated).
112+
*/
113+
onAfterPageLoad?: (to: string) => Awaitable<void>
110114
/**
111115
* Called after the route changes.
112116
*/

docs/zh/reference/runtime-api.md

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ interface Router {
102102
* 在页面组件加载前(history 状态更新后)调用。返回 `false` 表示取消导航
103103
*/
104104
onBeforePageLoad?: (to: string) => Awaitable<void | boolean>
105+
/**
106+
* 在页面组件加载后(页面组件实际更新前)调用
107+
*/
108+
onAfterPageLoad?: (to: string) => Awaitable<void>
105109
/**
106110
* 在路由更改后调用
107111
*/

src/client/app/router.ts

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export interface Router {
2929
* updated). Return `false` to cancel the navigation.
3030
*/
3131
onBeforePageLoad?: (to: string) => Awaitable<void | boolean>
32+
/**
33+
* Called after the page component is loaded (before the page component is updated).
34+
*/
35+
onAfterPageLoad?: (to: string) => Awaitable<void>
3236
/**
3337
* Called after the route changes.
3438
*/
@@ -94,6 +98,8 @@ export function createRouter(
9498
throw new Error(`Invalid route component: ${comp}`)
9599
}
96100

101+
await router.onAfterPageLoad?.(href)
102+
97103
route.path = inBrowser ? pendingPath : withBase(pendingPath)
98104
route.component = markRaw(comp)
99105
route.data = import.meta.env.PROD

0 commit comments

Comments
 (0)