blob: 931b6eeefb29a66ca159b319c37dd20bedbcf1ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { computed } from 'vue'
import { useRoute } from 'vue-router/composables'
/**
* Get information about the current route
*/
export function useRouteParameters() {
const route = useRoute()
/**
* Get the path of the current active directory
*/
const directory = computed<string>(
() => String(route.query.dir || '/')
// Remove any trailing slash but leave root slash
.replace(/^(.+)\/$/, '$1')
)
/**
* Get the current fileId used on the route
*/
const fileId = computed<number | null>(() => {
const fileId = Number.parseInt(route.params.fileid ?? '0') || null
return Number.isNaN(fileId) ? null : fileId
})
/**
* State of `openFile` route param
*/
const openFile = computed<boolean>(() => 'openFile' in route.params && route.params.openFile.toLocaleLowerCase() !== 'false')
return {
/** Path of currently open directory */
directory,
/** Current active fileId */
fileId,
/** Should the active node should be opened (`openFile` route param) */
openFile,
}
}
|