@falcondev-oss/nuxt-layers-base 0.35.7 → 0.35.9

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,27 @@
1
1
  import { useRouteParams } from '@vueuse/router'
2
2
 
3
- export function useRouteParamString(paramName: string) {
4
- const param = useRouteParams<string>(paramName)
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 route = useRoute()
15
+ const param = useRouteParams<string | undefined>(paramName)
5
16
 
6
17
  const paramRef = ref(param.value)
7
18
  const stop = watch(
8
19
  param,
9
20
  () => {
10
- if (typeof param.value !== 'string')
21
+ if (param.value !== undefined && typeof param.value !== 'string')
11
22
  throw new Error(`Route parameter '[${paramName}]' must be a string`)
23
+ if (!optional && param.value === undefined)
24
+ throw new Error(`Route parameter '[${paramName}]' is required`)
12
25
  paramRef.value = param.value
13
26
  },
14
27
  { immediate: true },
@@ -22,6 +35,13 @@ export function useRouteParamString(paramName: string) {
22
35
  return computed({
23
36
  get: () => paramRef.value,
24
37
  set: (value) => {
38
+ if (param.value === undefined && value !== undefined) {
39
+ void navigateTo({
40
+ name: `${String(route.name)}-${paramName}`,
41
+ params: { ...route.params, [paramName]: value },
42
+ })
43
+ return
44
+ }
25
45
  param.value = value
26
46
  },
27
47
  })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@falcondev-oss/nuxt-layers-base",
3
3
  "type": "module",
4
- "version": "0.35.7",
4
+ "version": "0.35.9",
5
5
  "description": "Nuxt layer with lots of useful helpers and @nuxt/ui components",
6
6
  "license": "MIT",
7
7
  "repository": {