@esmx/router-vue 3.0.0-rc.63 → 3.0.0-rc.65
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.
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +2 -1
- package/dist/index.test.mjs +2 -2
- package/dist/router-view.d.ts +0 -1
- package/dist/router-view.mjs +3 -5
- package/dist/use.d.ts +58 -0
- package/dist/use.mjs +11 -0
- package/package.json +3 -3
- package/src/index.test.ts +2 -2
- package/src/index.ts +2 -1
- package/src/router-view.ts +4 -10
- package/src/use.ts +73 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type * from './vue2';
|
|
2
2
|
export type * from './vue3';
|
|
3
|
-
export { useRouter, useRoute, useProvideRouter, useLink, getRoute, getRouter } from './use';
|
|
3
|
+
export { useRouter, useRoute, useProvideRouter, useLink, useRouterViewDepth, getRoute, getRouter } from './use';
|
|
4
4
|
export { RouterLink } from './router-link';
|
|
5
|
-
export { RouterView
|
|
5
|
+
export { RouterView } from './router-view';
|
|
6
6
|
export { RouterPlugin } from './plugin';
|
package/dist/index.mjs
CHANGED
|
@@ -3,9 +3,10 @@ export {
|
|
|
3
3
|
useRoute,
|
|
4
4
|
useProvideRouter,
|
|
5
5
|
useLink,
|
|
6
|
+
useRouterViewDepth,
|
|
6
7
|
getRoute,
|
|
7
8
|
getRouter
|
|
8
9
|
} from "./use.mjs";
|
|
9
10
|
export { RouterLink } from "./router-link.mjs";
|
|
10
|
-
export { RouterView
|
|
11
|
+
export { RouterView } from "./router-view.mjs";
|
|
11
12
|
export { RouterPlugin } from "./plugin.mjs";
|
package/dist/index.test.mjs
CHANGED
|
@@ -60,13 +60,13 @@ describe("index.ts - Package Entry Point", () => {
|
|
|
60
60
|
"useRoute",
|
|
61
61
|
"useProvideRouter",
|
|
62
62
|
"useLink",
|
|
63
|
+
"useRouterViewDepth",
|
|
63
64
|
// Options API
|
|
64
65
|
"getRouter",
|
|
65
66
|
"getRoute",
|
|
66
67
|
// Components
|
|
67
68
|
"RouterLink",
|
|
68
69
|
"RouterView",
|
|
69
|
-
"RouterViewDepth",
|
|
70
70
|
// Plugin
|
|
71
71
|
"RouterPlugin"
|
|
72
72
|
];
|
|
@@ -84,11 +84,11 @@ describe("index.ts - Package Entry Point", () => {
|
|
|
84
84
|
"useRoute",
|
|
85
85
|
"useProvideRouter",
|
|
86
86
|
"useLink",
|
|
87
|
+
"useRouterViewDepth",
|
|
87
88
|
"getRouter",
|
|
88
89
|
"getRoute",
|
|
89
90
|
"RouterLink",
|
|
90
91
|
"RouterView",
|
|
91
|
-
"RouterViewDepth",
|
|
92
92
|
"RouterPlugin"
|
|
93
93
|
];
|
|
94
94
|
const unexpectedExports = actualExports.filter(
|
package/dist/router-view.d.ts
CHANGED
package/dist/router-view.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { defineComponent, h
|
|
2
|
-
import { useRoute } from "./use.mjs";
|
|
1
|
+
import { defineComponent, h } from "vue";
|
|
2
|
+
import { _useRouterViewDepth, useRoute } from "./use.mjs";
|
|
3
3
|
import { resolveComponent } from "./util.mjs";
|
|
4
|
-
export const RouterViewDepth = Symbol("RouterViewDepth");
|
|
5
4
|
export const RouterView = defineComponent({
|
|
6
5
|
name: "RouterView",
|
|
7
6
|
setup() {
|
|
8
7
|
const route = useRoute();
|
|
9
|
-
const depth =
|
|
10
|
-
provide(RouterViewDepth, depth + 1);
|
|
8
|
+
const depth = _useRouterViewDepth(true);
|
|
11
9
|
return () => {
|
|
12
10
|
const matchedRoute = route.matched[depth];
|
|
13
11
|
const component = matchedRoute ? resolveComponent(matchedRoute.component) : null;
|
package/dist/use.d.ts
CHANGED
|
@@ -166,6 +166,64 @@ export declare function useRoute(): Route;
|
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
168
|
export declare function useProvideRouter(router: Router): void;
|
|
169
|
+
/**
|
|
170
|
+
* Get the current RouterView depth in nested routing scenarios.
|
|
171
|
+
* Returns the depth of the current RouterView component in the component tree.
|
|
172
|
+
* Useful for advanced routing scenarios where you need to know the nesting level.
|
|
173
|
+
*
|
|
174
|
+
* @param isRender - Whether this is used in a RouterView component that needs to provide depth for children (default: false)
|
|
175
|
+
* @returns Current RouterView depth (0 for root level, 1 for first nested level, etc.)
|
|
176
|
+
* @throws {Error} If called outside setup()
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```vue
|
|
180
|
+
* <template>
|
|
181
|
+
* <div>
|
|
182
|
+
* <p>Current RouterView depth: {{ depth }}</p>
|
|
183
|
+
* <RouterView />
|
|
184
|
+
* </div>
|
|
185
|
+
* </template>
|
|
186
|
+
*
|
|
187
|
+
* <script setup lang="ts">
|
|
188
|
+
* import { useRouterViewDepth } from '@esmx/router-vue';
|
|
189
|
+
*
|
|
190
|
+
* // Get current depth without providing for children
|
|
191
|
+
* const depth = useRouterViewDepth();
|
|
192
|
+
* console.log('Current RouterView depth:', depth); // 0, 1, 2, etc.
|
|
193
|
+
*
|
|
194
|
+
* // Get current depth and provide depth + 1 for children (used in RouterView component)
|
|
195
|
+
* const depth = useRouterViewDepth(true);
|
|
196
|
+
* </script>
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare function _useRouterViewDepth(isRender?: boolean): number;
|
|
200
|
+
/**
|
|
201
|
+
* Get the current RouterView depth in nested routing scenarios.
|
|
202
|
+
* Returns the depth of the current RouterView component in the component tree.
|
|
203
|
+
* Useful for advanced routing scenarios where you need to know the nesting level.
|
|
204
|
+
*
|
|
205
|
+
* @returns Current RouterView depth (0 for root level, 1 for first nested level, etc.)
|
|
206
|
+
* @throws {Error} If called outside setup()
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```vue
|
|
210
|
+
* <template>
|
|
211
|
+
* <div>
|
|
212
|
+
* <p>Current RouterView depth: {{ depth }}</p>
|
|
213
|
+
* <RouterView />
|
|
214
|
+
* </div>
|
|
215
|
+
* </template>
|
|
216
|
+
*
|
|
217
|
+
* <script setup lang="ts">
|
|
218
|
+
* import { useRouterViewDepth } from '@esmx/router-vue';
|
|
219
|
+
*
|
|
220
|
+
* // Get current depth without providing for children
|
|
221
|
+
* const depth = useRouterViewDepth();
|
|
222
|
+
* console.log('Current RouterView depth:', depth); // 0, 1, 2, etc.
|
|
223
|
+
* </script>
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export declare function useRouterViewDepth(): number;
|
|
169
227
|
/**
|
|
170
228
|
* Create reactive link helpers for navigation elements.
|
|
171
229
|
* Returns computed properties for link attributes, classes, and event handlers.
|
package/dist/use.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { createDependentProxy, createSymbolProperty } from "./util.mjs";
|
|
10
10
|
const ROUTER_CONTEXT_KEY = Symbol("router-context");
|
|
11
11
|
const ROUTER_INJECT_KEY = Symbol("router-inject");
|
|
12
|
+
const ROUTER_VIEW_DEPTH_KEY = Symbol("router-view-depth");
|
|
12
13
|
const ERROR_MESSAGES = {
|
|
13
14
|
SETUP_ONLY: (fnName) => "[@esmx/router-vue] ".concat(fnName, "() can only be called during setup()"),
|
|
14
15
|
CONTEXT_NOT_FOUND: "[@esmx/router-vue] Router context not found. Please ensure useProvideRouter() is called in a parent component."
|
|
@@ -79,6 +80,16 @@ export function useProvideRouter(router) {
|
|
|
79
80
|
});
|
|
80
81
|
onBeforeUnmount(unwatch);
|
|
81
82
|
}
|
|
83
|
+
export function _useRouterViewDepth(isRender) {
|
|
84
|
+
const depth = inject(ROUTER_VIEW_DEPTH_KEY, 0);
|
|
85
|
+
if (isRender) {
|
|
86
|
+
provide(ROUTER_VIEW_DEPTH_KEY, depth + 1);
|
|
87
|
+
}
|
|
88
|
+
return depth;
|
|
89
|
+
}
|
|
90
|
+
export function useRouterViewDepth() {
|
|
91
|
+
return _useRouterViewDepth();
|
|
92
|
+
}
|
|
82
93
|
export function useLink(props) {
|
|
83
94
|
const router = useRouter();
|
|
84
95
|
return computed(() => {
|
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"vue": "^3.5.0 || ^2.7.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@esmx/router": "3.0.0-rc.
|
|
53
|
+
"@esmx/router": "3.0.0-rc.65"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@biomejs/biome": "1.9.4",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vue": "3.5.13",
|
|
63
63
|
"vue2": "npm:vue@2.7.16"
|
|
64
64
|
},
|
|
65
|
-
"version": "3.0.0-rc.
|
|
65
|
+
"version": "3.0.0-rc.65",
|
|
66
66
|
"type": "module",
|
|
67
67
|
"private": false,
|
|
68
68
|
"exports": {
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"template",
|
|
82
82
|
"public"
|
|
83
83
|
],
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "3061beefe4d43c54ce66b75c2d95f193601d1289"
|
|
85
85
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -73,13 +73,13 @@ describe('index.ts - Package Entry Point', () => {
|
|
|
73
73
|
'useRoute',
|
|
74
74
|
'useProvideRouter',
|
|
75
75
|
'useLink',
|
|
76
|
+
'useRouterViewDepth',
|
|
76
77
|
// Options API
|
|
77
78
|
'getRouter',
|
|
78
79
|
'getRoute',
|
|
79
80
|
// Components
|
|
80
81
|
'RouterLink',
|
|
81
82
|
'RouterView',
|
|
82
|
-
'RouterViewDepth',
|
|
83
83
|
// Plugin
|
|
84
84
|
'RouterPlugin'
|
|
85
85
|
];
|
|
@@ -99,11 +99,11 @@ describe('index.ts - Package Entry Point', () => {
|
|
|
99
99
|
'useRoute',
|
|
100
100
|
'useProvideRouter',
|
|
101
101
|
'useLink',
|
|
102
|
+
'useRouterViewDepth',
|
|
102
103
|
'getRouter',
|
|
103
104
|
'getRoute',
|
|
104
105
|
'RouterLink',
|
|
105
106
|
'RouterView',
|
|
106
|
-
'RouterViewDepth',
|
|
107
107
|
'RouterPlugin'
|
|
108
108
|
];
|
|
109
109
|
|
package/src/index.ts
CHANGED
|
@@ -6,11 +6,12 @@ export {
|
|
|
6
6
|
useRoute,
|
|
7
7
|
useProvideRouter,
|
|
8
8
|
useLink,
|
|
9
|
+
useRouterViewDepth,
|
|
9
10
|
getRoute,
|
|
10
11
|
getRouter
|
|
11
12
|
} from './use';
|
|
12
13
|
|
|
13
14
|
export { RouterLink } from './router-link';
|
|
14
|
-
export { RouterView
|
|
15
|
+
export { RouterView } from './router-view';
|
|
15
16
|
|
|
16
17
|
export { RouterPlugin } from './plugin';
|
package/src/router-view.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { defineComponent, h
|
|
2
|
-
import { useRoute } from './use';
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { _useRouterViewDepth, useRoute } from './use';
|
|
3
3
|
import { resolveComponent } from './util';
|
|
4
4
|
|
|
5
|
-
export const RouterViewDepth = Symbol('RouterViewDepth');
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* RouterView component for rendering matched route components.
|
|
9
7
|
* Acts as a placeholder where route components are rendered based on the current route.
|
|
@@ -37,13 +35,9 @@ export const RouterView = defineComponent({
|
|
|
37
35
|
setup() {
|
|
38
36
|
const route = useRoute();
|
|
39
37
|
|
|
40
|
-
// Get current RouterView depth
|
|
38
|
+
// Get current RouterView depth and automatically provide depth + 1 for children
|
|
41
39
|
// This enables proper nested routing by tracking how deep we are in the component tree
|
|
42
|
-
const depth =
|
|
43
|
-
|
|
44
|
-
// Provide depth + 1 to child RouterView components
|
|
45
|
-
// This ensures each nested RouterView renders the correct route component
|
|
46
|
-
provide(RouterViewDepth, depth + 1);
|
|
40
|
+
const depth = _useRouterViewDepth(true);
|
|
47
41
|
|
|
48
42
|
return () => {
|
|
49
43
|
// Get the matched route configuration at current depth
|
package/src/use.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Route, Router, RouterLinkProps } from '@esmx/router';
|
|
2
2
|
import {
|
|
3
|
-
type Ref,
|
|
4
3
|
computed,
|
|
5
4
|
getCurrentInstance,
|
|
6
5
|
inject,
|
|
@@ -23,6 +22,7 @@ interface RouterContext {
|
|
|
23
22
|
|
|
24
23
|
const ROUTER_CONTEXT_KEY = Symbol('router-context');
|
|
25
24
|
const ROUTER_INJECT_KEY = Symbol('router-inject');
|
|
25
|
+
const ROUTER_VIEW_DEPTH_KEY = Symbol('router-view-depth');
|
|
26
26
|
|
|
27
27
|
const ERROR_MESSAGES = {
|
|
28
28
|
SETUP_ONLY: (fnName: string) =>
|
|
@@ -282,6 +282,78 @@ export function useProvideRouter(router: Router): void {
|
|
|
282
282
|
onBeforeUnmount(unwatch);
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Get the current RouterView depth in nested routing scenarios.
|
|
287
|
+
* Returns the depth of the current RouterView component in the component tree.
|
|
288
|
+
* Useful for advanced routing scenarios where you need to know the nesting level.
|
|
289
|
+
*
|
|
290
|
+
* @param isRender - Whether this is used in a RouterView component that needs to provide depth for children (default: false)
|
|
291
|
+
* @returns Current RouterView depth (0 for root level, 1 for first nested level, etc.)
|
|
292
|
+
* @throws {Error} If called outside setup()
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```vue
|
|
296
|
+
* <template>
|
|
297
|
+
* <div>
|
|
298
|
+
* <p>Current RouterView depth: {{ depth }}</p>
|
|
299
|
+
* <RouterView />
|
|
300
|
+
* </div>
|
|
301
|
+
* </template>
|
|
302
|
+
*
|
|
303
|
+
* <script setup lang="ts">
|
|
304
|
+
* import { useRouterViewDepth } from '@esmx/router-vue';
|
|
305
|
+
*
|
|
306
|
+
* // Get current depth without providing for children
|
|
307
|
+
* const depth = useRouterViewDepth();
|
|
308
|
+
* console.log('Current RouterView depth:', depth); // 0, 1, 2, etc.
|
|
309
|
+
*
|
|
310
|
+
* // Get current depth and provide depth + 1 for children (used in RouterView component)
|
|
311
|
+
* const depth = useRouterViewDepth(true);
|
|
312
|
+
* </script>
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
export function _useRouterViewDepth(isRender?: boolean): number {
|
|
316
|
+
// Get current RouterView depth from parent RouterView (if any)
|
|
317
|
+
// Default to 0 if no parent RouterView is found
|
|
318
|
+
const depth = inject(ROUTER_VIEW_DEPTH_KEY, 0);
|
|
319
|
+
|
|
320
|
+
if (isRender) {
|
|
321
|
+
// Provide depth + 1 to child RouterView components
|
|
322
|
+
provide(ROUTER_VIEW_DEPTH_KEY, depth + 1);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return depth;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the current RouterView depth in nested routing scenarios.
|
|
329
|
+
* Returns the depth of the current RouterView component in the component tree.
|
|
330
|
+
* Useful for advanced routing scenarios where you need to know the nesting level.
|
|
331
|
+
*
|
|
332
|
+
* @returns Current RouterView depth (0 for root level, 1 for first nested level, etc.)
|
|
333
|
+
* @throws {Error} If called outside setup()
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```vue
|
|
337
|
+
* <template>
|
|
338
|
+
* <div>
|
|
339
|
+
* <p>Current RouterView depth: {{ depth }}</p>
|
|
340
|
+
* <RouterView />
|
|
341
|
+
* </div>
|
|
342
|
+
* </template>
|
|
343
|
+
*
|
|
344
|
+
* <script setup lang="ts">
|
|
345
|
+
* import { useRouterViewDepth } from '@esmx/router-vue';
|
|
346
|
+
*
|
|
347
|
+
* // Get current depth without providing for children
|
|
348
|
+
* const depth = useRouterViewDepth();
|
|
349
|
+
* console.log('Current RouterView depth:', depth); // 0, 1, 2, etc.
|
|
350
|
+
* </script>
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
export function useRouterViewDepth(): number {
|
|
354
|
+
return _useRouterViewDepth();
|
|
355
|
+
}
|
|
356
|
+
|
|
285
357
|
/**
|
|
286
358
|
* Create reactive link helpers for navigation elements.
|
|
287
359
|
* Returns computed properties for link attributes, classes, and event handlers.
|