@falcondev-oss/nuxt-layers-base 0.35.6 → 0.35.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { useRouteParams } from '@vueuse/router'
|
|
2
2
|
|
|
3
|
-
export function useRouteParamString(
|
|
4
|
-
|
|
3
|
+
export function useRouteParamString(
|
|
4
|
+
paramName: string,
|
|
5
|
+
options?: { optional?: false },
|
|
6
|
+
): WritableComputedRef<string, string | undefined>
|
|
7
|
+
export function useRouteParamString(
|
|
8
|
+
paramName: string,
|
|
9
|
+
options: { optional: true },
|
|
10
|
+
): WritableComputedRef<string | undefined>
|
|
11
|
+
export function useRouteParamString(paramName: string, options?: { optional?: boolean }) {
|
|
12
|
+
const optional = options?.optional ?? false
|
|
13
|
+
|
|
14
|
+
const param = useRouteParams<string | undefined>(paramName)
|
|
5
15
|
|
|
6
16
|
const paramRef = ref(param.value)
|
|
7
17
|
const stop = watch(
|
|
8
18
|
param,
|
|
9
19
|
() => {
|
|
10
|
-
if (typeof param.value !== 'string')
|
|
20
|
+
if (param.value !== undefined && typeof param.value !== 'string')
|
|
11
21
|
throw new Error(`Route parameter '[${paramName}]' must be a string`)
|
|
22
|
+
if (!optional && param.value === undefined)
|
|
23
|
+
throw new Error(`Route parameter '[${paramName}]' is required`)
|
|
12
24
|
paramRef.value = param.value
|
|
13
25
|
},
|
|
14
26
|
{ immediate: true },
|
|
@@ -19,5 +31,10 @@ export function useRouteParamString(paramName: string) {
|
|
|
19
31
|
next()
|
|
20
32
|
})
|
|
21
33
|
|
|
22
|
-
return
|
|
34
|
+
return computed({
|
|
35
|
+
get: () => paramRef.value,
|
|
36
|
+
set: (value) => {
|
|
37
|
+
param.value = value
|
|
38
|
+
},
|
|
39
|
+
})
|
|
23
40
|
}
|