@esmx/router-vue 3.0.0-rc.105 → 3.0.0-rc.107
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/use.d.ts +18 -4
- package/dist/use.mjs +1 -3
- package/dist/use.test.mjs +4 -8
- package/package.json +3 -3
- package/src/use.test.ts +4 -8
- package/src/use.ts +19 -7
package/dist/use.d.ts
CHANGED
|
@@ -219,12 +219,26 @@ export declare function _useRouterViewDepth(isRender?: boolean): number;
|
|
|
219
219
|
*/
|
|
220
220
|
export declare function useRouterViewDepth(): number;
|
|
221
221
|
/**
|
|
222
|
-
* Get
|
|
223
|
-
*
|
|
222
|
+
* Get the current RouterView depth in nested routing scenarios.
|
|
223
|
+
* Returns the depth of the current RouterView component in the component tree.
|
|
224
|
+
* Useful for advanced routing scenarios where you need to know the nesting level.
|
|
224
225
|
*
|
|
225
226
|
* @param instance - Vue component instance to start from
|
|
226
|
-
* @returns
|
|
227
|
-
*
|
|
227
|
+
* @returns Current RouterView depth (0 for root level, 1 for first nested level, etc.)
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* // Options API usage
|
|
232
|
+
* import { defineComponent } from 'vue';
|
|
233
|
+
* import { getRouterViewDepth } from '@esmx/router-vue';
|
|
234
|
+
*
|
|
235
|
+
* export default defineComponent({
|
|
236
|
+
* mounted() {
|
|
237
|
+
* const depth = getRouterViewDepth(this);
|
|
238
|
+
* console.log('Current RouterView depth:', depth); // 0, 1, 2, etc.
|
|
239
|
+
* }
|
|
240
|
+
* });
|
|
241
|
+
* ```
|
|
228
242
|
*/
|
|
229
243
|
export declare function getRouterViewDepth(instance: VueInstance): number;
|
|
230
244
|
/**
|
package/dist/use.mjs
CHANGED
|
@@ -113,9 +113,7 @@ export function getRouterViewDepth(instance) {
|
|
|
113
113
|
if (typeof value === "number") return value;
|
|
114
114
|
current = current.$parent;
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
"[@esmx/router-vue] RouterView depth not found. Please ensure a RouterView exists in ancestor components."
|
|
118
|
-
);
|
|
116
|
+
return 0;
|
|
119
117
|
}
|
|
120
118
|
export function useLink(props) {
|
|
121
119
|
const router = useRouter();
|
package/dist/use.test.mjs
CHANGED
|
@@ -295,12 +295,12 @@ describe("Router Vue Integration", () => {
|
|
|
295
295
|
await nextTick();
|
|
296
296
|
expect(observedDepth).toBe(3);
|
|
297
297
|
});
|
|
298
|
-
it("should
|
|
299
|
-
let
|
|
298
|
+
it("should return 0 when no RouterView ancestor exists", async () => {
|
|
299
|
+
let observedDepth;
|
|
300
300
|
const Probe = defineComponent({
|
|
301
301
|
setup() {
|
|
302
302
|
const p = getCurrentInstance().proxy;
|
|
303
|
-
|
|
303
|
+
observedDepth = getRouterViewDepth(p);
|
|
304
304
|
return () => h("div");
|
|
305
305
|
}
|
|
306
306
|
});
|
|
@@ -313,11 +313,7 @@ describe("Router Vue Integration", () => {
|
|
|
313
313
|
app = createApp(TestApp);
|
|
314
314
|
app.mount("#app");
|
|
315
315
|
await nextTick();
|
|
316
|
-
expect(
|
|
317
|
-
new Error(
|
|
318
|
-
"[@esmx/router-vue] RouterView depth not found. Please ensure a RouterView exists in ancestor components."
|
|
319
|
-
)
|
|
320
|
-
);
|
|
316
|
+
expect(observedDepth).toBe(0);
|
|
321
317
|
});
|
|
322
318
|
it("should return 0 for useRouterViewDepth without RouterView", async () => {
|
|
323
319
|
let observed = -1;
|
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.107"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@biomejs/biome": "2.3.7",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vue": "3.5.23",
|
|
63
63
|
"vue2": "npm:vue@2.7.16"
|
|
64
64
|
},
|
|
65
|
-
"version": "3.0.0-rc.
|
|
65
|
+
"version": "3.0.0-rc.107",
|
|
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": "28155d02a6222ce59a24f3f707359e8e89e4f36d"
|
|
85
85
|
}
|
package/src/use.test.ts
CHANGED
|
@@ -381,13 +381,13 @@ describe('Router Vue Integration', () => {
|
|
|
381
381
|
expect(observedDepth).toBe(3);
|
|
382
382
|
});
|
|
383
383
|
|
|
384
|
-
it('should
|
|
385
|
-
let
|
|
384
|
+
it('should return 0 when no RouterView ancestor exists', async () => {
|
|
385
|
+
let observedDepth: number | undefined;
|
|
386
386
|
|
|
387
387
|
const Probe = defineComponent({
|
|
388
388
|
setup() {
|
|
389
389
|
const p = getCurrentInstance()!.proxy as any;
|
|
390
|
-
|
|
390
|
+
observedDepth = getRouterViewDepth(p);
|
|
391
391
|
return () => h('div');
|
|
392
392
|
}
|
|
393
393
|
});
|
|
@@ -403,11 +403,7 @@ describe('Router Vue Integration', () => {
|
|
|
403
403
|
app.mount('#app');
|
|
404
404
|
await nextTick();
|
|
405
405
|
|
|
406
|
-
expect(
|
|
407
|
-
new Error(
|
|
408
|
-
'[@esmx/router-vue] RouterView depth not found. Please ensure a RouterView exists in ancestor components.'
|
|
409
|
-
)
|
|
410
|
-
);
|
|
406
|
+
expect(observedDepth).toBe(0);
|
|
411
407
|
});
|
|
412
408
|
|
|
413
409
|
it('should return 0 for useRouterViewDepth without RouterView', async () => {
|
package/src/use.ts
CHANGED
|
@@ -358,12 +358,26 @@ export function useRouterViewDepth(): number {
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
/**
|
|
361
|
-
* Get
|
|
362
|
-
*
|
|
361
|
+
* Get the current RouterView depth in nested routing scenarios.
|
|
362
|
+
* Returns the depth of the current RouterView component in the component tree.
|
|
363
|
+
* Useful for advanced routing scenarios where you need to know the nesting level.
|
|
363
364
|
*
|
|
364
365
|
* @param instance - Vue component instance to start from
|
|
365
|
-
* @returns
|
|
366
|
-
*
|
|
366
|
+
* @returns Current RouterView depth (0 for root level, 1 for first nested level, etc.)
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* // Options API usage
|
|
371
|
+
* import { defineComponent } from 'vue';
|
|
372
|
+
* import { getRouterViewDepth } from '@esmx/router-vue';
|
|
373
|
+
*
|
|
374
|
+
* export default defineComponent({
|
|
375
|
+
* mounted() {
|
|
376
|
+
* const depth = getRouterViewDepth(this);
|
|
377
|
+
* console.log('Current RouterView depth:', depth); // 0, 1, 2, etc.
|
|
378
|
+
* }
|
|
379
|
+
* });
|
|
380
|
+
* ```
|
|
367
381
|
*/
|
|
368
382
|
export function getRouterViewDepth(instance: VueInstance): number {
|
|
369
383
|
let current = instance.$parent;
|
|
@@ -372,9 +386,7 @@ export function getRouterViewDepth(instance: VueInstance): number {
|
|
|
372
386
|
if (typeof value === 'number') return value;
|
|
373
387
|
current = current.$parent;
|
|
374
388
|
}
|
|
375
|
-
|
|
376
|
-
'[@esmx/router-vue] RouterView depth not found. Please ensure a RouterView exists in ancestor components.'
|
|
377
|
-
);
|
|
389
|
+
return 0;
|
|
378
390
|
}
|
|
379
391
|
|
|
380
392
|
/**
|