-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathhelpers.ts
More file actions
66 lines (50 loc) · 1.18 KB
/
Copy pathhelpers.ts
File metadata and controls
66 lines (50 loc) · 1.18 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { Ref } from 'vue';
import type { RouteLocationNormalized, Router } from 'vue-router';
function makeHelper<T>(
name: string,
helperFunc: () => T,
globalPropKey: string,
) {
let _value: T;
return (value?: T) => {
if (_value != null) {
return _value;
}
if (value == null) {
value = helperFunc();
}
if (value == null) {
value =
getCurrentInstance()?.appContext.app.config.globalProperties[
globalPropKey
];
}
if (value == null) {
throw new Error(`Unable to load ${name}.`);
}
if (process.env.CLIENT) {
_value = value;
}
return value;
};
}
export const router = makeHelper('router', useRouter, '$router');
export const $quasar = makeHelper('Quasar', useQuasar, '$q');
// Route
let _route: Ref<RouteLocationNormalized>;
export function route(router_?: Router) {
if (_route != null) {
return _route;
}
let route: Ref<RouteLocationNormalized> | undefined;
if (route == null) {
route = router(router_).currentRoute;
}
if (route == null) {
throw new Error('Unable to load route.');
}
if (process.env.CLIENT) {
_route = route;
}
return route;
}