aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/composables/useBeforeNavigation.ts
blob: 38b72e40fb33a7cc012c04bbc26ddea814d32bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import type { NavigationGuard } from 'vue-router'

import { onUnmounted } from 'vue'
import { useRouter } from 'vue-router/composables'

/**
 * Helper until we use Vue-Router v4 (Vue3).
 *
 * @param fn - The navigation guard
 */
export function onBeforeNavigation(fn: NavigationGuard) {
	const router = useRouter()
	const remove = router.beforeResolve(fn)
	onUnmounted(remove)
}