Skip to content

Vue

在创建 Router 之前安装一次:

ts
import { install } from "@revfanc/guard"

install()

组件中使用 Composition API 管理对应层:

vue
<script setup lang="ts">
import { onUnmounted } from "vue"
import { create } from "@revfanc/guard"

const stop = create(async (resolve) => {
  if (await confirmLeaving()) resolve()
})

onUnmounted(stop)
</script>

多个组件各自调用 create()即可形成 LIFO 栈。使用 KeepAlive时,在 onActivated()注册,在 onDeactivated()同步停止。

Released under the MIT License.