@esmx/router-vue 3.0.0-rc.103

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +570 -0
  3. package/README.zh-CN.md +570 -0
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.mjs +13 -0
  6. package/dist/index.test.d.ts +1 -0
  7. package/dist/index.test.mjs +216 -0
  8. package/dist/plugin.d.ts +61 -0
  9. package/dist/plugin.mjs +41 -0
  10. package/dist/plugin.test.d.ts +1 -0
  11. package/dist/plugin.test.mjs +631 -0
  12. package/dist/router-link.d.ts +220 -0
  13. package/dist/router-link.mjs +119 -0
  14. package/dist/router-link.test.d.ts +1 -0
  15. package/dist/router-link.test.mjs +663 -0
  16. package/dist/router-view.d.ts +31 -0
  17. package/dist/router-view.mjs +15 -0
  18. package/dist/router-view.test.d.ts +1 -0
  19. package/dist/router-view.test.mjs +676 -0
  20. package/dist/run-with-context.test.d.ts +1 -0
  21. package/dist/run-with-context.test.mjs +57 -0
  22. package/dist/use.d.ts +260 -0
  23. package/dist/use.mjs +125 -0
  24. package/dist/use.test.d.ts +1 -0
  25. package/dist/use.test.mjs +381 -0
  26. package/dist/util.d.ts +20 -0
  27. package/dist/util.mjs +49 -0
  28. package/dist/util.test.d.ts +4 -0
  29. package/dist/util.test.mjs +604 -0
  30. package/dist/vue2.d.ts +15 -0
  31. package/dist/vue2.mjs +0 -0
  32. package/dist/vue3.d.ts +13 -0
  33. package/dist/vue3.mjs +0 -0
  34. package/package.json +85 -0
  35. package/src/index.test.ts +273 -0
  36. package/src/index.ts +15 -0
  37. package/src/plugin.test.ts +812 -0
  38. package/src/plugin.ts +107 -0
  39. package/src/router-link.test.ts +830 -0
  40. package/src/router-link.ts +172 -0
  41. package/src/router-view.test.ts +840 -0
  42. package/src/router-view.ts +59 -0
  43. package/src/run-with-context.test.ts +64 -0
  44. package/src/use.test.ts +484 -0
  45. package/src/use.ts +416 -0
  46. package/src/util.test.ts +760 -0
  47. package/src/util.ts +85 -0
  48. package/src/vue2.ts +18 -0
  49. package/src/vue3.ts +15 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,676 @@
1
+ import { Router, RouterMode } from "@esmx/router";
2
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
3
+ import { createApp, defineComponent, h, inject, nextTick, provide } from "vue";
4
+ import { RouterView } from "./router-view.mjs";
5
+ import { useProvideRouter } from "./use.mjs";
6
+ const HomeComponent = defineComponent({
7
+ name: "HomeComponent",
8
+ setup() {
9
+ return () => h("div", { class: "home" }, "Home Page");
10
+ }
11
+ });
12
+ const AboutComponent = defineComponent({
13
+ name: "AboutComponent",
14
+ setup() {
15
+ return () => h("div", { class: "about" }, "About Page");
16
+ }
17
+ });
18
+ const UserComponent = defineComponent({
19
+ name: "UserComponent",
20
+ setup() {
21
+ return () => h("div", { class: "user" }, "User Component");
22
+ }
23
+ });
24
+ const ESModuleComponent = {
25
+ __esModule: true,
26
+ default: defineComponent({
27
+ name: "ESModuleComponent",
28
+ setup() {
29
+ return () => h("div", { class: "es-module" }, "ES Module Component");
30
+ }
31
+ })
32
+ };
33
+ describe("router-view.ts - RouterView Component", () => {
34
+ let router;
35
+ let testContainer;
36
+ beforeEach(async () => {
37
+ testContainer = document.createElement("div");
38
+ testContainer.id = "test-app";
39
+ document.body.appendChild(testContainer);
40
+ const routes = [
41
+ {
42
+ path: "/",
43
+ component: HomeComponent,
44
+ meta: { title: "Home" }
45
+ },
46
+ {
47
+ path: "/about",
48
+ component: AboutComponent,
49
+ meta: { title: "About" }
50
+ },
51
+ {
52
+ path: "/users/:id",
53
+ component: UserComponent,
54
+ meta: { title: "User" }
55
+ },
56
+ {
57
+ path: "/es-module",
58
+ component: ESModuleComponent,
59
+ meta: { title: "ES Module" }
60
+ }
61
+ ];
62
+ router = new Router({
63
+ root: "#test-app",
64
+ routes,
65
+ mode: RouterMode.memory,
66
+ base: new URL("http://localhost:8000/")
67
+ });
68
+ await router.replace("/");
69
+ await new Promise((resolve) => setTimeout(resolve, 10));
70
+ });
71
+ afterEach(() => {
72
+ if (testContainer.parentNode) {
73
+ testContainer.parentNode.removeChild(testContainer);
74
+ }
75
+ if (router) {
76
+ router.destroy();
77
+ }
78
+ });
79
+ describe("Basic Functionality", () => {
80
+ it("should render matched route component at depth 0", async () => {
81
+ const TestApp = defineComponent({
82
+ setup() {
83
+ useProvideRouter(router);
84
+ return () => h("div", [h(RouterView)]);
85
+ }
86
+ });
87
+ const app = createApp(TestApp);
88
+ app.mount(testContainer);
89
+ await nextTick();
90
+ expect(testContainer.textContent).toContain("Home Page");
91
+ app.unmount();
92
+ });
93
+ it("should render different components when route changes", async () => {
94
+ const TestApp = defineComponent({
95
+ setup() {
96
+ useProvideRouter(router);
97
+ return () => h("div", [h(RouterView)]);
98
+ }
99
+ });
100
+ const app = createApp(TestApp);
101
+ app.mount(testContainer);
102
+ await nextTick();
103
+ expect(testContainer.textContent).toContain("Home Page");
104
+ await router.push("/about");
105
+ await nextTick();
106
+ expect(testContainer.textContent).toContain("About Page");
107
+ app.unmount();
108
+ });
109
+ it("should handle routes with parameters", async () => {
110
+ const TestApp = defineComponent({
111
+ setup() {
112
+ useProvideRouter(router);
113
+ return () => h("div", [h(RouterView)]);
114
+ }
115
+ });
116
+ const app = createApp(TestApp);
117
+ app.mount(testContainer);
118
+ await router.push("/users/123");
119
+ await nextTick();
120
+ expect(testContainer.textContent).toContain("User Component");
121
+ app.unmount();
122
+ });
123
+ });
124
+ describe("Component Resolution", () => {
125
+ it("should resolve ES module components correctly", async () => {
126
+ const TestApp = defineComponent({
127
+ setup() {
128
+ useProvideRouter(router);
129
+ return () => h("div", [h(RouterView)]);
130
+ }
131
+ });
132
+ const app = createApp(TestApp);
133
+ app.mount(testContainer);
134
+ await router.push("/es-module");
135
+ await nextTick();
136
+ expect(testContainer.textContent).toContain("ES Module Component");
137
+ app.unmount();
138
+ });
139
+ it("should handle function components", async () => {
140
+ const FunctionComponent = () => h("div", "Function Component");
141
+ const routes = [
142
+ {
143
+ path: "/function",
144
+ component: FunctionComponent,
145
+ meta: { title: "Function" }
146
+ }
147
+ ];
148
+ const functionRouter = new Router({
149
+ root: "#test-app",
150
+ routes,
151
+ mode: RouterMode.memory,
152
+ base: new URL("http://localhost:8000/")
153
+ });
154
+ await functionRouter.replace("/function");
155
+ await new Promise((resolve) => setTimeout(resolve, 10));
156
+ const TestApp = defineComponent({
157
+ setup() {
158
+ useProvideRouter(functionRouter);
159
+ return () => h("div", [h(RouterView)]);
160
+ }
161
+ });
162
+ const app = createApp(TestApp);
163
+ app.mount(testContainer);
164
+ await nextTick();
165
+ expect(testContainer.textContent).toContain("Function Component");
166
+ app.unmount();
167
+ functionRouter.destroy();
168
+ });
169
+ });
170
+ describe("Depth Tracking", () => {
171
+ it("should inject depth 0 by default", async () => {
172
+ let injectedDepth;
173
+ const RouterViewDepth = Symbol("RouterViewDepth");
174
+ const TestRouterView = defineComponent({
175
+ name: "TestRouterView",
176
+ setup() {
177
+ injectedDepth = inject(RouterViewDepth, -1);
178
+ return () => h(RouterView);
179
+ }
180
+ });
181
+ const TestApp = defineComponent({
182
+ setup() {
183
+ useProvideRouter(router);
184
+ return () => h("div", [h(TestRouterView)]);
185
+ }
186
+ });
187
+ const app = createApp(TestApp);
188
+ app.mount(testContainer);
189
+ await nextTick();
190
+ expect(injectedDepth).toBe(-1);
191
+ app.unmount();
192
+ });
193
+ it("should provide correct depth in nested RouterViews", async () => {
194
+ let parentDepth;
195
+ let childDepth;
196
+ const RouterViewDepth = Symbol("RouterViewDepth");
197
+ const ParentTestComponent = defineComponent({
198
+ name: "ParentTestComponent",
199
+ setup() {
200
+ parentDepth = inject(RouterViewDepth, -1);
201
+ provide(RouterViewDepth, 0);
202
+ return () => h("div", [h("span", "Parent"), h(ChildTestComponent)]);
203
+ }
204
+ });
205
+ const ChildTestComponent = defineComponent({
206
+ name: "ChildTestComponent",
207
+ setup() {
208
+ childDepth = inject(RouterViewDepth, -1);
209
+ return () => h("div", "Child");
210
+ }
211
+ });
212
+ const TestApp = defineComponent({
213
+ setup() {
214
+ useProvideRouter(router);
215
+ return () => h("div", [h(ParentTestComponent)]);
216
+ }
217
+ });
218
+ const app = createApp(TestApp);
219
+ app.mount(testContainer);
220
+ await nextTick();
221
+ expect(parentDepth).toBe(-1);
222
+ expect(childDepth).toBe(0);
223
+ app.unmount();
224
+ });
225
+ it("should handle nested RouterViews with correct depth", async () => {
226
+ const Level1Component = defineComponent({
227
+ name: "Level1Component",
228
+ setup() {
229
+ return () => h("div", [h("span", "Level 1"), h(RouterView)]);
230
+ }
231
+ });
232
+ const Level2Component = defineComponent({
233
+ name: "Level2Component",
234
+ setup() {
235
+ return () => h("div", "Level 2");
236
+ }
237
+ });
238
+ const nestedRoutes = [
239
+ {
240
+ path: "/level1",
241
+ component: Level1Component,
242
+ children: [
243
+ {
244
+ path: "level2",
245
+ component: Level2Component
246
+ }
247
+ ]
248
+ }
249
+ ];
250
+ const nestedRouter = new Router({
251
+ root: "#test-app",
252
+ routes: nestedRoutes,
253
+ mode: RouterMode.memory,
254
+ base: new URL("http://localhost:8000/")
255
+ });
256
+ await nestedRouter.replace("/level1/level2");
257
+ await new Promise((resolve) => setTimeout(resolve, 10));
258
+ const TestApp = defineComponent({
259
+ setup() {
260
+ useProvideRouter(nestedRouter);
261
+ return () => h("div", [h(RouterView)]);
262
+ }
263
+ });
264
+ const app = createApp(TestApp);
265
+ app.mount(testContainer);
266
+ await nextTick();
267
+ expect(testContainer.textContent).toContain("Level 1");
268
+ expect(testContainer.textContent).toContain("Level 2");
269
+ app.unmount();
270
+ nestedRouter.destroy();
271
+ });
272
+ });
273
+ describe("Edge Cases and Error Handling", () => {
274
+ it("should render null when no route matches at current depth", async () => {
275
+ const RouterViewDepth = Symbol("RouterViewDepth");
276
+ const DeepRouterView = defineComponent({
277
+ name: "DeepRouterView",
278
+ setup() {
279
+ const currentDepth = inject(RouterViewDepth, 0);
280
+ provide(RouterViewDepth, currentDepth + 1);
281
+ return () => h(RouterView);
282
+ }
283
+ });
284
+ const TestApp = defineComponent({
285
+ setup() {
286
+ useProvideRouter(router);
287
+ return () => h("div", [
288
+ h("span", "App"),
289
+ h(RouterView),
290
+ h(DeepRouterView)
291
+ ]);
292
+ }
293
+ });
294
+ const app = createApp(TestApp);
295
+ app.mount(testContainer);
296
+ await nextTick();
297
+ expect(testContainer.textContent).toContain("App");
298
+ expect(testContainer.textContent).toContain("Home Page");
299
+ app.unmount();
300
+ });
301
+ it("should handle null components gracefully", async () => {
302
+ var _a, _b, _c;
303
+ const routesWithNull = [
304
+ {
305
+ path: "/null-component",
306
+ component: null,
307
+ meta: { title: "Null Component" }
308
+ }
309
+ ];
310
+ const nullRouter = new Router({
311
+ root: "#test-app",
312
+ routes: routesWithNull,
313
+ mode: RouterMode.memory,
314
+ base: new URL("http://localhost:8000/")
315
+ });
316
+ await nullRouter.replace("/null-component");
317
+ await new Promise((resolve) => setTimeout(resolve, 10));
318
+ const TestApp = defineComponent({
319
+ setup() {
320
+ useProvideRouter(nullRouter);
321
+ return () => h("div", [h("span", "App"), h(RouterView)]);
322
+ }
323
+ });
324
+ const app = createApp(TestApp);
325
+ app.mount(testContainer);
326
+ await nextTick();
327
+ expect((_a = testContainer.textContent) == null ? void 0 : _a.trim()).toBe("App");
328
+ expect((_b = testContainer.querySelector("div")) == null ? void 0 : _b.children.length).toBe(1);
329
+ expect((_c = testContainer.querySelector("span")) == null ? void 0 : _c.textContent).toBe(
330
+ "App"
331
+ );
332
+ app.unmount();
333
+ nullRouter.destroy();
334
+ });
335
+ it("should handle non-existent routes", async () => {
336
+ var _a, _b, _c;
337
+ const nonExistentRouter = new Router({
338
+ root: "#test-app",
339
+ routes: [
340
+ {
341
+ path: "/",
342
+ component: null
343
+ }
344
+ ],
345
+ mode: RouterMode.memory,
346
+ base: new URL("http://localhost:8000/")
347
+ });
348
+ await nonExistentRouter.replace("/");
349
+ await new Promise((resolve) => setTimeout(resolve, 10));
350
+ const TestApp = defineComponent({
351
+ setup() {
352
+ useProvideRouter(nonExistentRouter);
353
+ return () => h("div", [h("span", "App"), h(RouterView)]);
354
+ }
355
+ });
356
+ const app = createApp(TestApp);
357
+ app.mount(testContainer);
358
+ await nonExistentRouter.push("/non-existent");
359
+ await nextTick();
360
+ await new Promise((resolve) => setTimeout(resolve, 10));
361
+ expect((_a = testContainer.textContent) == null ? void 0 : _a.trim()).toBe("App");
362
+ expect((_b = testContainer.querySelector("div")) == null ? void 0 : _b.children.length).toBe(1);
363
+ expect((_c = testContainer.querySelector("span")) == null ? void 0 : _c.textContent).toBe(
364
+ "App"
365
+ );
366
+ app.unmount();
367
+ nonExistentRouter.destroy();
368
+ });
369
+ it("should handle malformed ES modules", async () => {
370
+ const MalformedModule = {
371
+ __esModule: true,
372
+ default: null
373
+ };
374
+ const malformedRoutes = [
375
+ {
376
+ path: "/malformed",
377
+ component: MalformedModule,
378
+ meta: { title: "Malformed" }
379
+ }
380
+ ];
381
+ const malformedRouter = new Router({
382
+ root: "#test-app",
383
+ routes: malformedRoutes,
384
+ mode: RouterMode.memory,
385
+ base: new URL("http://localhost:8000/")
386
+ });
387
+ await malformedRouter.replace("/malformed");
388
+ await new Promise((resolve) => setTimeout(resolve, 10));
389
+ const TestApp = defineComponent({
390
+ setup() {
391
+ useProvideRouter(malformedRouter);
392
+ return () => h("div", [h("span", "App"), h(RouterView)]);
393
+ }
394
+ });
395
+ const app = createApp(TestApp);
396
+ app.mount(testContainer);
397
+ await nextTick();
398
+ expect(testContainer.textContent).toBe("App");
399
+ app.unmount();
400
+ malformedRouter.destroy();
401
+ });
402
+ });
403
+ describe("Component Properties", () => {
404
+ it("should have correct component name", () => {
405
+ expect(RouterView.name).toBe("RouterView");
406
+ });
407
+ it("should be a valid Vue component", () => {
408
+ expect(RouterView).toHaveProperty("setup");
409
+ expect(typeof RouterView.setup).toBe("function");
410
+ });
411
+ it("should not define props", () => {
412
+ expect(RouterView.props).toBeUndefined();
413
+ });
414
+ });
415
+ describe("Integration Tests", () => {
416
+ it("should re-render when route changes", async () => {
417
+ const TestApp = defineComponent({
418
+ setup() {
419
+ useProvideRouter(router);
420
+ return () => h("div", [h(RouterView)]);
421
+ }
422
+ });
423
+ const app = createApp(TestApp);
424
+ app.mount(testContainer);
425
+ await nextTick();
426
+ expect(testContainer.textContent).toContain("Home Page");
427
+ await router.push("/about");
428
+ await nextTick();
429
+ expect(testContainer.textContent).toContain("About Page");
430
+ await router.push("/users/123");
431
+ await nextTick();
432
+ expect(testContainer.textContent).toContain("User Component");
433
+ app.unmount();
434
+ });
435
+ it("should work with router navigation methods", async () => {
436
+ const TestApp = defineComponent({
437
+ setup() {
438
+ useProvideRouter(router);
439
+ return () => h("div", [h(RouterView)]);
440
+ }
441
+ });
442
+ const app = createApp(TestApp);
443
+ app.mount(testContainer);
444
+ await router.push("/about");
445
+ await nextTick();
446
+ expect(testContainer.textContent).toContain("About Page");
447
+ await router.replace("/users/456");
448
+ await nextTick();
449
+ expect(testContainer.textContent).toContain("User Component");
450
+ await router.back();
451
+ await nextTick();
452
+ expect(testContainer.textContent).toContain("Home Page");
453
+ app.unmount();
454
+ });
455
+ });
456
+ describe("compilePath as Key", () => {
457
+ it("should use compilePath as key for component rendering", async () => {
458
+ let mountCount = 0;
459
+ const TrackedComponent = defineComponent({
460
+ name: "TrackedComponent",
461
+ setup() {
462
+ mountCount++;
463
+ return () => h(
464
+ "div",
465
+ { class: "tracked" },
466
+ "Mounted ".concat(mountCount, " times")
467
+ );
468
+ }
469
+ });
470
+ const routes = [
471
+ {
472
+ path: "/route1",
473
+ component: TrackedComponent
474
+ },
475
+ {
476
+ path: "/route2",
477
+ component: TrackedComponent
478
+ }
479
+ ];
480
+ const testRouter = new Router({
481
+ root: "#test-app",
482
+ routes,
483
+ mode: RouterMode.memory,
484
+ base: new URL("http://localhost:8000/")
485
+ });
486
+ await testRouter.replace("/route1");
487
+ await new Promise((resolve) => setTimeout(resolve, 10));
488
+ const TestApp = defineComponent({
489
+ setup() {
490
+ useProvideRouter(testRouter);
491
+ return () => h("div", [h(RouterView)]);
492
+ }
493
+ });
494
+ const app = createApp(TestApp);
495
+ app.mount(testContainer);
496
+ await nextTick();
497
+ expect(mountCount).toBe(1);
498
+ expect(testContainer.textContent).toContain("Mounted 1 times");
499
+ await testRouter.push("/route2");
500
+ await nextTick();
501
+ expect(mountCount).toBe(2);
502
+ expect(testContainer.textContent).toContain("Mounted 2 times");
503
+ await testRouter.push("/route1");
504
+ await nextTick();
505
+ expect(mountCount).toBe(3);
506
+ expect(testContainer.textContent).toContain("Mounted 3 times");
507
+ app.unmount();
508
+ testRouter.destroy();
509
+ });
510
+ it("should force re-render when compilePath changes for same route", async () => {
511
+ let mountCount = 0;
512
+ const TrackedComponent = defineComponent({
513
+ name: "TrackedComponent",
514
+ setup() {
515
+ mountCount++;
516
+ return () => h("div", { class: "tracked" }, "Mount #".concat(mountCount));
517
+ }
518
+ });
519
+ const routes = [
520
+ {
521
+ path: "/test",
522
+ component: TrackedComponent
523
+ }
524
+ ];
525
+ const testRouter = new Router({
526
+ root: "#test-app",
527
+ routes,
528
+ mode: RouterMode.memory,
529
+ base: new URL("http://localhost:8000/")
530
+ });
531
+ await testRouter.replace("/test");
532
+ await new Promise((resolve) => setTimeout(resolve, 10));
533
+ const TestApp = defineComponent({
534
+ setup() {
535
+ useProvideRouter(testRouter);
536
+ return () => h("div", [h(RouterView)]);
537
+ }
538
+ });
539
+ const app = createApp(TestApp);
540
+ app.mount(testContainer);
541
+ await nextTick();
542
+ expect(mountCount).toBe(1);
543
+ expect(testContainer.textContent).toContain("Mount #1");
544
+ const newRoutes = [
545
+ {
546
+ path: "/test",
547
+ component: TrackedComponent,
548
+ meta: { updated: true }
549
+ }
550
+ ];
551
+ const newRouter = new Router({
552
+ root: "#test-app",
553
+ routes: newRoutes,
554
+ mode: RouterMode.memory,
555
+ base: new URL("http://localhost:8000/")
556
+ });
557
+ await newRouter.replace("/test");
558
+ await new Promise((resolve) => setTimeout(resolve, 10));
559
+ app.unmount();
560
+ const NewTestApp = defineComponent({
561
+ setup() {
562
+ useProvideRouter(newRouter);
563
+ return () => h("div", [h(RouterView)]);
564
+ }
565
+ });
566
+ const newApp = createApp(NewTestApp);
567
+ newApp.mount(testContainer);
568
+ await nextTick();
569
+ expect(mountCount).toBe(2);
570
+ expect(testContainer.textContent).toContain("Mount #2");
571
+ newApp.unmount();
572
+ newRouter.destroy();
573
+ });
574
+ it("should handle same component with same compilePath without unnecessary re-renders", async () => {
575
+ let mountCount = 0;
576
+ const TrackedComponent = defineComponent({
577
+ name: "TrackedComponent",
578
+ setup() {
579
+ mountCount++;
580
+ return () => h("div", { class: "tracked" }, "Component");
581
+ }
582
+ });
583
+ const routes = [
584
+ {
585
+ path: "/test",
586
+ component: TrackedComponent
587
+ }
588
+ ];
589
+ const testRouter = new Router({
590
+ root: "#test-app",
591
+ routes,
592
+ mode: RouterMode.memory,
593
+ base: new URL("http://localhost:8000/")
594
+ });
595
+ await testRouter.replace("/test");
596
+ await new Promise((resolve) => setTimeout(resolve, 10));
597
+ const TestApp = defineComponent({
598
+ setup() {
599
+ useProvideRouter(testRouter);
600
+ return () => h("div", [h(RouterView)]);
601
+ }
602
+ });
603
+ const app = createApp(TestApp);
604
+ app.mount(testContainer);
605
+ await nextTick();
606
+ expect(mountCount).toBe(1);
607
+ await testRouter.push("/");
608
+ await nextTick();
609
+ await testRouter.push("/test");
610
+ await nextTick();
611
+ expect(mountCount).toBe(1);
612
+ app.unmount();
613
+ testRouter.destroy();
614
+ });
615
+ it("should work with nested routes and compilePath keys", async () => {
616
+ let parentMountCount = 0;
617
+ let childMountCount = 0;
618
+ const ParentComponent = defineComponent({
619
+ name: "ParentComponent",
620
+ setup() {
621
+ parentMountCount++;
622
+ return () => h("div", [
623
+ h("h1", "Parent Mount #".concat(parentMountCount)),
624
+ h(RouterView)
625
+ ]);
626
+ }
627
+ });
628
+ const ChildComponent = defineComponent({
629
+ name: "ChildComponent",
630
+ setup() {
631
+ childMountCount++;
632
+ return () => h(
633
+ "div",
634
+ { class: "child" },
635
+ "Child Mount #".concat(childMountCount)
636
+ );
637
+ }
638
+ });
639
+ const nestedRoutes = [
640
+ {
641
+ path: "/parent",
642
+ component: ParentComponent,
643
+ children: [
644
+ {
645
+ path: "child",
646
+ component: ChildComponent
647
+ }
648
+ ]
649
+ }
650
+ ];
651
+ const nestedRouter = new Router({
652
+ root: "#test-app",
653
+ routes: nestedRoutes,
654
+ mode: RouterMode.memory,
655
+ base: new URL("http://localhost:8000/")
656
+ });
657
+ await nestedRouter.replace("/parent/child");
658
+ await new Promise((resolve) => setTimeout(resolve, 10));
659
+ const TestApp = defineComponent({
660
+ setup() {
661
+ useProvideRouter(nestedRouter);
662
+ return () => h("div", [h(RouterView)]);
663
+ }
664
+ });
665
+ const app = createApp(TestApp);
666
+ app.mount(testContainer);
667
+ await nextTick();
668
+ expect(parentMountCount).toBe(1);
669
+ expect(childMountCount).toBe(1);
670
+ expect(testContainer.textContent).toContain("Parent Mount #1");
671
+ expect(testContainer.textContent).toContain("Child Mount #1");
672
+ app.unmount();
673
+ nestedRouter.destroy();
674
+ });
675
+ });
676
+ });
@@ -0,0 +1 @@
1
+ export {};