Skip to content

Commit 71f65e1

Browse files
author
jingwenzheng
committed
feat: bool | promise<bool>
1 parent dc42b70 commit 71f65e1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/core/src/back.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ const backCheck = (deltaCount: number, backHid?: string) => {
5454
const reBack = () => {
5555
/// 再次返回的时候 设置 重新设置 back id
5656
setLastBackHookId(backHid)
57-
setLeaveBefore(instance)
57+
setLeaveBefore(instance, undefined)
5858
window.history.go(-deltaCount)
5959
}
6060

6161
const result = hook()
62-
if (typeof result === 'function') {
63-
if ((await result()) === true && isSampleBatchId()) reBack()
64-
} else {
62+
if (typeof result === 'boolean') {
6563
if (result && isSampleBatchId()) reBack()
64+
} else {
65+
if ((await result) === true && isSampleBatchId()) reBack()
6666
}
6767
})
6868
}

packages/core/src/hooks/leaveBefore.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
* 在页面即将返回的时候,会调用hook方法,返回是否可以返回
1010
* 该方法,如果在某个页面多次注册,会覆盖请注意
1111
*/
12-
const useLeaveBefore = (hook: () => boolean | (() => Promise<boolean>)) => {
12+
const useLeaveBefore = (hook: (() => boolean) | (() => Promise<boolean>)) => {
1313
setValueToAppContext(
1414
getCurrentInstance()?.appContext,
1515
ExtensionHooks.onLeaveBefore,
@@ -18,7 +18,7 @@ const useLeaveBefore = (hook: () => boolean | (() => Promise<boolean>)) => {
1818
}
1919

2020
const getLeaveBefore = (context: AppContext | undefined) =>
21-
getValueFromAppContext<() => boolean | (() => Promise<boolean>)>(
21+
getValueFromAppContext<(() => boolean) | (() => Promise<boolean>)>(
2222
context,
2323
ExtensionHooks.onLeaveBefore,
2424
)

0 commit comments

Comments
 (0)