@esmx/router-vue 3.0.0-rc.17 → 3.0.0-rc.20
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/LICENSE +1 -1
- package/README.md +563 -0
- package/README.zh-CN.md +563 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +11 -4
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.mjs +206 -0
- package/dist/plugin.d.ts +61 -11
- package/dist/plugin.mjs +32 -16
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.mjs +436 -0
- package/dist/router-link.d.ts +202 -0
- package/dist/router-link.mjs +84 -0
- package/dist/router-link.test.d.ts +1 -0
- package/dist/router-link.test.mjs +456 -0
- package/dist/router-view.d.ts +31 -0
- package/dist/router-view.mjs +17 -0
- package/dist/router-view.test.d.ts +1 -0
- package/dist/router-view.test.mjs +459 -0
- package/dist/use.d.ts +198 -3
- package/dist/use.mjs +75 -9
- package/dist/use.test.d.ts +1 -0
- package/dist/use.test.mjs +461 -0
- package/dist/util.d.ts +7 -0
- package/dist/util.mjs +24 -0
- package/dist/util.test.d.ts +1 -0
- package/dist/util.test.mjs +319 -0
- package/dist/vue2.d.ts +13 -0
- package/dist/vue2.mjs +0 -0
- package/dist/vue3.d.ts +13 -0
- package/dist/vue3.mjs +0 -0
- package/package.json +31 -14
- package/src/index.test.ts +263 -0
- package/src/index.ts +16 -4
- package/src/plugin.test.ts +574 -0
- package/src/plugin.ts +92 -31
- package/src/router-link.test.ts +569 -0
- package/src/router-link.ts +148 -0
- package/src/router-view.test.ts +599 -0
- package/src/router-view.ts +62 -0
- package/src/use.test.ts +616 -0
- package/src/use.ts +307 -11
- package/src/util.test.ts +418 -0
- package/src/util.ts +32 -0
- package/src/vue2.ts +16 -0
- package/src/vue3.ts +15 -0
- package/dist/link.d.ts +0 -101
- package/dist/link.mjs +0 -103
- package/dist/symbols.d.ts +0 -3
- package/dist/symbols.mjs +0 -3
- package/dist/view.d.ts +0 -21
- package/dist/view.mjs +0 -75
- package/src/link.ts +0 -177
- package/src/symbols.ts +0 -8
- package/src/view.ts +0 -95
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { Router, RouterMode } from "@esmx/router";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { createApp, defineComponent, h, nextTick } from "vue";
|
|
4
|
+
import { RouterPlugin } from "./plugin.mjs";
|
|
5
|
+
import { RouterLink } from "./router-link.mjs";
|
|
6
|
+
import { RouterView } from "./router-view.mjs";
|
|
7
|
+
import { useProvideRouter } from "./use.mjs";
|
|
8
|
+
describe("plugin.ts - RouterPlugin", () => {
|
|
9
|
+
let router;
|
|
10
|
+
let app;
|
|
11
|
+
let container;
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
container = document.createElement("div");
|
|
14
|
+
container.id = "test-app";
|
|
15
|
+
document.body.appendChild(container);
|
|
16
|
+
const routes = [
|
|
17
|
+
{
|
|
18
|
+
path: "/",
|
|
19
|
+
component: defineComponent({
|
|
20
|
+
name: "Home",
|
|
21
|
+
render: () => h("div", "Home Page")
|
|
22
|
+
}),
|
|
23
|
+
meta: { title: "Home" }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
path: "/about",
|
|
27
|
+
component: defineComponent({
|
|
28
|
+
name: "About",
|
|
29
|
+
render: () => h("div", "About Page")
|
|
30
|
+
}),
|
|
31
|
+
meta: { title: "About" }
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
router = new Router({
|
|
35
|
+
mode: RouterMode.memory,
|
|
36
|
+
routes,
|
|
37
|
+
base: new URL("http://localhost:3000/")
|
|
38
|
+
});
|
|
39
|
+
await router.replace("/");
|
|
40
|
+
await nextTick();
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
if (app) {
|
|
44
|
+
app.unmount();
|
|
45
|
+
}
|
|
46
|
+
if (router) {
|
|
47
|
+
router.destroy();
|
|
48
|
+
}
|
|
49
|
+
if (container == null ? void 0 : container.parentNode) {
|
|
50
|
+
container.parentNode.removeChild(container);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
describe("Plugin Installation", () => {
|
|
54
|
+
it("should install plugin without errors", () => {
|
|
55
|
+
app = createApp({
|
|
56
|
+
setup() {
|
|
57
|
+
useProvideRouter(router);
|
|
58
|
+
return () => h("div", "Test App");
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
expect(() => {
|
|
62
|
+
app.use(RouterPlugin);
|
|
63
|
+
}).not.toThrow();
|
|
64
|
+
});
|
|
65
|
+
it("should throw error for invalid Vue app instance", () => {
|
|
66
|
+
const invalidApp = {};
|
|
67
|
+
expect(() => {
|
|
68
|
+
RouterPlugin.install(invalidApp);
|
|
69
|
+
}).toThrow("[@esmx/router-vue] Invalid Vue app instance");
|
|
70
|
+
});
|
|
71
|
+
it("should throw error for null app instance", () => {
|
|
72
|
+
expect(() => {
|
|
73
|
+
RouterPlugin.install(null);
|
|
74
|
+
}).toThrow();
|
|
75
|
+
});
|
|
76
|
+
it("should throw error for undefined app instance", () => {
|
|
77
|
+
expect(() => {
|
|
78
|
+
RouterPlugin.install(void 0);
|
|
79
|
+
}).toThrow();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("Global Properties Injection", () => {
|
|
83
|
+
it("should inject $router and $route properties", async () => {
|
|
84
|
+
app = createApp({
|
|
85
|
+
setup() {
|
|
86
|
+
useProvideRouter(router);
|
|
87
|
+
return () => h("div", "Test App");
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
app.use(RouterPlugin);
|
|
91
|
+
app.mount(container);
|
|
92
|
+
await nextTick();
|
|
93
|
+
const globalProperties = app.config.globalProperties;
|
|
94
|
+
const routerDescriptor = Object.getOwnPropertyDescriptor(
|
|
95
|
+
globalProperties,
|
|
96
|
+
"$router"
|
|
97
|
+
);
|
|
98
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
99
|
+
globalProperties,
|
|
100
|
+
"$route"
|
|
101
|
+
);
|
|
102
|
+
expect(routerDescriptor).toBeDefined();
|
|
103
|
+
expect(routeDescriptor).toBeDefined();
|
|
104
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.get).toBeDefined();
|
|
105
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.get).toBeDefined();
|
|
106
|
+
expect(typeof (routerDescriptor == null ? void 0 : routerDescriptor.get)).toBe("function");
|
|
107
|
+
expect(typeof (routeDescriptor == null ? void 0 : routeDescriptor.get)).toBe("function");
|
|
108
|
+
});
|
|
109
|
+
it("should provide reactive $route property", async () => {
|
|
110
|
+
app = createApp({
|
|
111
|
+
setup() {
|
|
112
|
+
useProvideRouter(router);
|
|
113
|
+
return () => h("div", "Test App");
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
app.use(RouterPlugin);
|
|
117
|
+
app.mount(container);
|
|
118
|
+
await nextTick();
|
|
119
|
+
await router.push("/about");
|
|
120
|
+
await nextTick();
|
|
121
|
+
const globalProperties = app.config.globalProperties;
|
|
122
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
123
|
+
globalProperties,
|
|
124
|
+
"$route"
|
|
125
|
+
);
|
|
126
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.get).toBeDefined();
|
|
127
|
+
expect(typeof (routeDescriptor == null ? void 0 : routeDescriptor.get)).toBe("function");
|
|
128
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.enumerable).toBe(false);
|
|
129
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.configurable).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
it("should provide consistent $router instance across components", async () => {
|
|
132
|
+
const ChildComponent = defineComponent({
|
|
133
|
+
render() {
|
|
134
|
+
return h("div", "Child");
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
app = createApp({
|
|
138
|
+
setup() {
|
|
139
|
+
useProvideRouter(router);
|
|
140
|
+
return () => h("div", [h("div", "Parent"), h(ChildComponent)]);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
app.use(RouterPlugin);
|
|
144
|
+
app.mount(container);
|
|
145
|
+
await nextTick();
|
|
146
|
+
const globalProperties = app.config.globalProperties;
|
|
147
|
+
const routerDescriptor = Object.getOwnPropertyDescriptor(
|
|
148
|
+
globalProperties,
|
|
149
|
+
"$router"
|
|
150
|
+
);
|
|
151
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
152
|
+
globalProperties,
|
|
153
|
+
"$route"
|
|
154
|
+
);
|
|
155
|
+
expect(routerDescriptor).toBeDefined();
|
|
156
|
+
expect(routeDescriptor).toBeDefined();
|
|
157
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.get).toBeDefined();
|
|
158
|
+
expect(typeof (routerDescriptor == null ? void 0 : routerDescriptor.get)).toBe("function");
|
|
159
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.get).toBeDefined();
|
|
160
|
+
expect(typeof (routeDescriptor == null ? void 0 : routeDescriptor.get)).toBe("function");
|
|
161
|
+
});
|
|
162
|
+
it("should actually call $router getter when accessed in component", async () => {
|
|
163
|
+
let routerResult = null;
|
|
164
|
+
const TestComponent = defineComponent({
|
|
165
|
+
mounted() {
|
|
166
|
+
routerResult = this.$router;
|
|
167
|
+
},
|
|
168
|
+
render() {
|
|
169
|
+
return h("div", "Test Component");
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
app = createApp({
|
|
173
|
+
setup() {
|
|
174
|
+
useProvideRouter(router);
|
|
175
|
+
return () => h(TestComponent);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
app.use(RouterPlugin);
|
|
179
|
+
app.mount(container);
|
|
180
|
+
await nextTick();
|
|
181
|
+
expect(routerResult).toBe(router);
|
|
182
|
+
expect(routerResult).toBeInstanceOf(Router);
|
|
183
|
+
});
|
|
184
|
+
it("should actually call $route getter when accessed in component", async () => {
|
|
185
|
+
let routeResult = null;
|
|
186
|
+
const TestComponent = defineComponent({
|
|
187
|
+
mounted() {
|
|
188
|
+
routeResult = this.$route;
|
|
189
|
+
},
|
|
190
|
+
render() {
|
|
191
|
+
return h("div", "Test Component");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
app = createApp({
|
|
195
|
+
setup() {
|
|
196
|
+
useProvideRouter(router);
|
|
197
|
+
return () => h(TestComponent);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
app.use(RouterPlugin);
|
|
201
|
+
app.mount(container);
|
|
202
|
+
await nextTick();
|
|
203
|
+
await router.push("/about");
|
|
204
|
+
await nextTick();
|
|
205
|
+
expect(routeResult).toBeTruthy();
|
|
206
|
+
expect(routeResult).toHaveProperty("path", "/about");
|
|
207
|
+
expect(routeResult).toHaveProperty("meta.title", "About");
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
describe("Component Registration", () => {
|
|
211
|
+
it("should register components with correct names", () => {
|
|
212
|
+
app = createApp({
|
|
213
|
+
setup() {
|
|
214
|
+
useProvideRouter(router);
|
|
215
|
+
return () => h("div", "Test App");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
app.use(RouterPlugin);
|
|
219
|
+
const globalComponents = app._context.components;
|
|
220
|
+
expect(globalComponents).toHaveProperty("RouterLink");
|
|
221
|
+
expect(globalComponents).toHaveProperty("RouterView");
|
|
222
|
+
expect(globalComponents.RouterLink).toBe(RouterLink);
|
|
223
|
+
expect(globalComponents.RouterView).toBe(RouterView);
|
|
224
|
+
});
|
|
225
|
+
it("should register RouterLink component for global use", async () => {
|
|
226
|
+
app = createApp({
|
|
227
|
+
setup() {
|
|
228
|
+
useProvideRouter(router);
|
|
229
|
+
return () => h("div", "Test App with RouterLink available");
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
app.use(RouterPlugin);
|
|
233
|
+
app.mount(container);
|
|
234
|
+
await nextTick();
|
|
235
|
+
const globalComponents = app._context.components;
|
|
236
|
+
expect(globalComponents.RouterLink).toBeDefined();
|
|
237
|
+
expect(typeof globalComponents.RouterLink).toBe("object");
|
|
238
|
+
});
|
|
239
|
+
it("should register RouterView component for global use", async () => {
|
|
240
|
+
app = createApp({
|
|
241
|
+
setup() {
|
|
242
|
+
useProvideRouter(router);
|
|
243
|
+
return () => h("div", "Test App with RouterView available");
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
app.use(RouterPlugin);
|
|
247
|
+
app.mount(container);
|
|
248
|
+
await nextTick();
|
|
249
|
+
const globalComponents = app._context.components;
|
|
250
|
+
expect(globalComponents.RouterView).toBeDefined();
|
|
251
|
+
expect(typeof globalComponents.RouterView).toBe("object");
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
describe("Error Handling", () => {
|
|
255
|
+
it("should handle missing router context in global properties", () => {
|
|
256
|
+
const mockComponent = {
|
|
257
|
+
$: {
|
|
258
|
+
provides: {}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const target = {};
|
|
262
|
+
Object.defineProperties(target, {
|
|
263
|
+
$router: {
|
|
264
|
+
get() {
|
|
265
|
+
return require("./use").getRouter(mockComponent);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
expect(() => {
|
|
270
|
+
target.$router;
|
|
271
|
+
}).toThrow();
|
|
272
|
+
});
|
|
273
|
+
it("should handle missing router context in $route property", () => {
|
|
274
|
+
const mockComponent = {
|
|
275
|
+
$: {
|
|
276
|
+
provides: {}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const target = {};
|
|
280
|
+
Object.defineProperties(target, {
|
|
281
|
+
$route: {
|
|
282
|
+
get() {
|
|
283
|
+
return require("./use").getRoute(mockComponent);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
expect(() => {
|
|
288
|
+
target.$route;
|
|
289
|
+
}).toThrow();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
describe("Plugin Integration", () => {
|
|
293
|
+
it("should work with multiple plugin installations", () => {
|
|
294
|
+
app = createApp({
|
|
295
|
+
setup() {
|
|
296
|
+
useProvideRouter(router);
|
|
297
|
+
return () => h("div", "Test App");
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
app.use(RouterPlugin);
|
|
301
|
+
app.use(RouterPlugin);
|
|
302
|
+
expect(() => {
|
|
303
|
+
app.mount(container);
|
|
304
|
+
}).not.toThrow();
|
|
305
|
+
});
|
|
306
|
+
it("should maintain global properties after installation", async () => {
|
|
307
|
+
app = createApp({
|
|
308
|
+
setup() {
|
|
309
|
+
useProvideRouter(router);
|
|
310
|
+
return () => h("div", "Test App");
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
app.use(RouterPlugin);
|
|
314
|
+
app.mount(container);
|
|
315
|
+
await nextTick();
|
|
316
|
+
const globalProperties = app.config.globalProperties;
|
|
317
|
+
const routerDescriptor = Object.getOwnPropertyDescriptor(
|
|
318
|
+
globalProperties,
|
|
319
|
+
"$router"
|
|
320
|
+
);
|
|
321
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
322
|
+
globalProperties,
|
|
323
|
+
"$route"
|
|
324
|
+
);
|
|
325
|
+
expect(routerDescriptor).toBeDefined();
|
|
326
|
+
expect(routeDescriptor).toBeDefined();
|
|
327
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.get).toBeDefined();
|
|
328
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.get).toBeDefined();
|
|
329
|
+
expect(typeof (routerDescriptor == null ? void 0 : routerDescriptor.get)).toBe("function");
|
|
330
|
+
expect(typeof (routeDescriptor == null ? void 0 : routeDescriptor.get)).toBe("function");
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
describe("Type Safety", () => {
|
|
334
|
+
it("should provide properly typed global properties", async () => {
|
|
335
|
+
app = createApp({
|
|
336
|
+
setup() {
|
|
337
|
+
useProvideRouter(router);
|
|
338
|
+
return () => h("div", "Test App");
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
app.use(RouterPlugin);
|
|
342
|
+
app.mount(container);
|
|
343
|
+
await nextTick();
|
|
344
|
+
const globalProperties = app.config.globalProperties;
|
|
345
|
+
const routerDescriptor = Object.getOwnPropertyDescriptor(
|
|
346
|
+
globalProperties,
|
|
347
|
+
"$router"
|
|
348
|
+
);
|
|
349
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
350
|
+
globalProperties,
|
|
351
|
+
"$route"
|
|
352
|
+
);
|
|
353
|
+
expect(routerDescriptor).toBeDefined();
|
|
354
|
+
expect(routeDescriptor).toBeDefined();
|
|
355
|
+
expect(typeof (routerDescriptor == null ? void 0 : routerDescriptor.get)).toBe("function");
|
|
356
|
+
expect(typeof (routeDescriptor == null ? void 0 : routeDescriptor.get)).toBe("function");
|
|
357
|
+
expect(
|
|
358
|
+
Object.prototype.hasOwnProperty.call(
|
|
359
|
+
globalProperties,
|
|
360
|
+
"$router"
|
|
361
|
+
)
|
|
362
|
+
).toBe(true);
|
|
363
|
+
expect(
|
|
364
|
+
Object.prototype.hasOwnProperty.call(globalProperties, "$route")
|
|
365
|
+
).toBe(true);
|
|
366
|
+
});
|
|
367
|
+
it("should provide correct component types", () => {
|
|
368
|
+
app = createApp({
|
|
369
|
+
setup() {
|
|
370
|
+
useProvideRouter(router);
|
|
371
|
+
return () => h("div", "Test App");
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
app.use(RouterPlugin);
|
|
375
|
+
const globalComponents = app._context.components;
|
|
376
|
+
expect(globalComponents.RouterLink.name).toBe("RouterLink");
|
|
377
|
+
expect(globalComponents.RouterView.name).toBe("RouterView");
|
|
378
|
+
const routerLinkComponent = globalComponents.RouterLink;
|
|
379
|
+
const routerViewComponent = globalComponents.RouterView;
|
|
380
|
+
expect(typeof routerLinkComponent.setup).toBe("function");
|
|
381
|
+
expect(typeof routerViewComponent.setup).toBe("function");
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
describe("Advanced Plugin Features", () => {
|
|
385
|
+
it("should support property descriptor configuration", () => {
|
|
386
|
+
const testApp = {
|
|
387
|
+
config: {
|
|
388
|
+
globalProperties: {}
|
|
389
|
+
},
|
|
390
|
+
component: (name, component) => {
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
RouterPlugin.install(testApp);
|
|
394
|
+
const routerDescriptor = Object.getOwnPropertyDescriptor(
|
|
395
|
+
testApp.config.globalProperties,
|
|
396
|
+
"$router"
|
|
397
|
+
);
|
|
398
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
399
|
+
testApp.config.globalProperties,
|
|
400
|
+
"$route"
|
|
401
|
+
);
|
|
402
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.get).toBeDefined();
|
|
403
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.enumerable).toBe(false);
|
|
404
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.configurable).toBe(false);
|
|
405
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.get).toBeDefined();
|
|
406
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.enumerable).toBe(false);
|
|
407
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.configurable).toBe(false);
|
|
408
|
+
});
|
|
409
|
+
it("should handle different app instance structures", () => {
|
|
410
|
+
const minimalApp = {
|
|
411
|
+
config: {
|
|
412
|
+
globalProperties: {}
|
|
413
|
+
},
|
|
414
|
+
component: () => {
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
expect(() => {
|
|
418
|
+
RouterPlugin.install(minimalApp);
|
|
419
|
+
}).not.toThrow();
|
|
420
|
+
const routerDescriptor = Object.getOwnPropertyDescriptor(
|
|
421
|
+
minimalApp.config.globalProperties,
|
|
422
|
+
"$router"
|
|
423
|
+
);
|
|
424
|
+
const routeDescriptor = Object.getOwnPropertyDescriptor(
|
|
425
|
+
minimalApp.config.globalProperties,
|
|
426
|
+
"$route"
|
|
427
|
+
);
|
|
428
|
+
expect(routerDescriptor).toBeDefined();
|
|
429
|
+
expect(routeDescriptor).toBeDefined();
|
|
430
|
+
expect(routerDescriptor == null ? void 0 : routerDescriptor.get).toBeDefined();
|
|
431
|
+
expect(routeDescriptor == null ? void 0 : routeDescriptor.get).toBeDefined();
|
|
432
|
+
expect(typeof (routerDescriptor == null ? void 0 : routerDescriptor.get)).toBe("function");
|
|
433
|
+
expect(typeof (routeDescriptor == null ? void 0 : routeDescriptor.get)).toBe("function");
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { RouteLayerOptions, RouteLocationInput, RouteMatchType, RouterLinkType } from '@esmx/router';
|
|
2
|
+
import { type PropType } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* RouterLink component for navigation.
|
|
5
|
+
* Renders an anchor tag with proper navigation behavior and active state management.
|
|
6
|
+
*
|
|
7
|
+
* @param props - Component properties
|
|
8
|
+
* @param props.to - Target route location to navigate to
|
|
9
|
+
* @param props.type - Navigation type ('push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer')
|
|
10
|
+
* @param props.replace - Use type='replace' instead
|
|
11
|
+
* @param props.exact - How to match the active state ('include' | 'exact' | 'route')
|
|
12
|
+
* @param props.activeClass - CSS class to apply when link is active
|
|
13
|
+
* @param props.event - Event(s) that trigger navigation
|
|
14
|
+
* @param props.tag - Custom tag to render instead of 'a'
|
|
15
|
+
* @param props.layerOptions - Layer options for layer-based navigation
|
|
16
|
+
* @param slots - Component slots
|
|
17
|
+
* @param slots.default - Default slot content
|
|
18
|
+
* @returns Vue component instance
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```vue
|
|
22
|
+
* <template>
|
|
23
|
+
* <nav>
|
|
24
|
+
* <!-- Basic navigation -->
|
|
25
|
+
* <RouterLink to="/home">Home</RouterLink>
|
|
26
|
+
* <RouterLink to="/about">About</RouterLink>
|
|
27
|
+
*
|
|
28
|
+
* <!-- With custom styling -->
|
|
29
|
+
* <RouterLink
|
|
30
|
+
* to="/dashboard"
|
|
31
|
+
* active-class="nav-active"
|
|
32
|
+
* >
|
|
33
|
+
* Dashboard
|
|
34
|
+
* </RouterLink>
|
|
35
|
+
*
|
|
36
|
+
* <!-- Replace navigation -->
|
|
37
|
+
* <RouterLink to="/login" type="replace">Login</RouterLink>
|
|
38
|
+
*
|
|
39
|
+
* <!-- Custom tag and exact matching -->
|
|
40
|
+
* <RouterLink
|
|
41
|
+
* to="/contact"
|
|
42
|
+
* exact="exact"
|
|
43
|
+
* tag="button"
|
|
44
|
+
* class="btn"
|
|
45
|
+
* >
|
|
46
|
+
* Contact
|
|
47
|
+
* </RouterLink>
|
|
48
|
+
* </nav>
|
|
49
|
+
* </template>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const RouterLink: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
53
|
+
/**
|
|
54
|
+
* Target route location to navigate to.
|
|
55
|
+
* Can be a string path or route location object.
|
|
56
|
+
* @example '/home' | { path: '/user', query: { id: '123' } }
|
|
57
|
+
*/
|
|
58
|
+
to: {
|
|
59
|
+
type: PropType<RouteLocationInput>;
|
|
60
|
+
required: true;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Navigation type for the link.
|
|
64
|
+
* @default 'push'
|
|
65
|
+
* @example 'push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer'
|
|
66
|
+
*/
|
|
67
|
+
type: {
|
|
68
|
+
type: PropType<RouterLinkType>;
|
|
69
|
+
default: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use 'type="replace"' instead
|
|
73
|
+
* @example replace={true} → type="replace"
|
|
74
|
+
*/
|
|
75
|
+
replace: {
|
|
76
|
+
type: BooleanConstructor;
|
|
77
|
+
default: boolean;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* How to match the active state.
|
|
81
|
+
* - 'include': Match if current route includes this path
|
|
82
|
+
* - 'exact': Match only if routes are exactly the same
|
|
83
|
+
* - 'route': Match based on route configuration
|
|
84
|
+
* @default 'include'
|
|
85
|
+
*/
|
|
86
|
+
exact: {
|
|
87
|
+
type: PropType<RouteMatchType>;
|
|
88
|
+
default: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* CSS class to apply when link is active (route matches).
|
|
92
|
+
* @example 'nav-active' | 'selected'
|
|
93
|
+
*/
|
|
94
|
+
activeClass: {
|
|
95
|
+
type: StringConstructor;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Event(s) that trigger navigation. Can be string or array of strings.
|
|
99
|
+
* @default 'click'
|
|
100
|
+
* @example 'click' | ['click', 'mouseenter']
|
|
101
|
+
*/
|
|
102
|
+
event: {
|
|
103
|
+
type: PropType<string | string[]>;
|
|
104
|
+
default: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Custom tag to render instead of 'a'.
|
|
108
|
+
* @default 'a'
|
|
109
|
+
* @example 'button' | 'div' | 'span'
|
|
110
|
+
*/
|
|
111
|
+
tag: {
|
|
112
|
+
type: StringConstructor;
|
|
113
|
+
default: string;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Layer options for layer-based navigation.
|
|
117
|
+
* Only used when type='pushLayer'.
|
|
118
|
+
* @example { zIndex: 1000, autoPush: false, routerOptions: { mode: 'memory' } }
|
|
119
|
+
*/
|
|
120
|
+
layerOptions: {
|
|
121
|
+
type: PropType<RouteLayerOptions>;
|
|
122
|
+
};
|
|
123
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
126
|
+
/**
|
|
127
|
+
* Target route location to navigate to.
|
|
128
|
+
* Can be a string path or route location object.
|
|
129
|
+
* @example '/home' | { path: '/user', query: { id: '123' } }
|
|
130
|
+
*/
|
|
131
|
+
to: {
|
|
132
|
+
type: PropType<RouteLocationInput>;
|
|
133
|
+
required: true;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Navigation type for the link.
|
|
137
|
+
* @default 'push'
|
|
138
|
+
* @example 'push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer'
|
|
139
|
+
*/
|
|
140
|
+
type: {
|
|
141
|
+
type: PropType<RouterLinkType>;
|
|
142
|
+
default: string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* @deprecated Use 'type="replace"' instead
|
|
146
|
+
* @example replace={true} → type="replace"
|
|
147
|
+
*/
|
|
148
|
+
replace: {
|
|
149
|
+
type: BooleanConstructor;
|
|
150
|
+
default: boolean;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* How to match the active state.
|
|
154
|
+
* - 'include': Match if current route includes this path
|
|
155
|
+
* - 'exact': Match only if routes are exactly the same
|
|
156
|
+
* - 'route': Match based on route configuration
|
|
157
|
+
* @default 'include'
|
|
158
|
+
*/
|
|
159
|
+
exact: {
|
|
160
|
+
type: PropType<RouteMatchType>;
|
|
161
|
+
default: string;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* CSS class to apply when link is active (route matches).
|
|
165
|
+
* @example 'nav-active' | 'selected'
|
|
166
|
+
*/
|
|
167
|
+
activeClass: {
|
|
168
|
+
type: StringConstructor;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Event(s) that trigger navigation. Can be string or array of strings.
|
|
172
|
+
* @default 'click'
|
|
173
|
+
* @example 'click' | ['click', 'mouseenter']
|
|
174
|
+
*/
|
|
175
|
+
event: {
|
|
176
|
+
type: PropType<string | string[]>;
|
|
177
|
+
default: string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Custom tag to render instead of 'a'.
|
|
181
|
+
* @default 'a'
|
|
182
|
+
* @example 'button' | 'div' | 'span'
|
|
183
|
+
*/
|
|
184
|
+
tag: {
|
|
185
|
+
type: StringConstructor;
|
|
186
|
+
default: string;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Layer options for layer-based navigation.
|
|
190
|
+
* Only used when type='pushLayer'.
|
|
191
|
+
* @example { zIndex: 1000, autoPush: false, routerOptions: { mode: 'memory' } }
|
|
192
|
+
*/
|
|
193
|
+
layerOptions: {
|
|
194
|
+
type: PropType<RouteLayerOptions>;
|
|
195
|
+
};
|
|
196
|
+
}>> & Readonly<{}>, {
|
|
197
|
+
type: RouterLinkType;
|
|
198
|
+
replace: boolean;
|
|
199
|
+
exact: RouteMatchType;
|
|
200
|
+
event: string | string[];
|
|
201
|
+
tag: string;
|
|
202
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|