@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.
- package/LICENSE +21 -0
- package/README.md +570 -0
- package/README.zh-CN.md +570 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +13 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.mjs +216 -0
- package/dist/plugin.d.ts +61 -0
- package/dist/plugin.mjs +41 -0
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.mjs +631 -0
- package/dist/router-link.d.ts +220 -0
- package/dist/router-link.mjs +119 -0
- package/dist/router-link.test.d.ts +1 -0
- package/dist/router-link.test.mjs +663 -0
- package/dist/router-view.d.ts +31 -0
- package/dist/router-view.mjs +15 -0
- package/dist/router-view.test.d.ts +1 -0
- package/dist/router-view.test.mjs +676 -0
- package/dist/run-with-context.test.d.ts +1 -0
- package/dist/run-with-context.test.mjs +57 -0
- package/dist/use.d.ts +260 -0
- package/dist/use.mjs +125 -0
- package/dist/use.test.d.ts +1 -0
- package/dist/use.test.mjs +381 -0
- package/dist/util.d.ts +20 -0
- package/dist/util.mjs +49 -0
- package/dist/util.test.d.ts +4 -0
- package/dist/util.test.mjs +604 -0
- package/dist/vue2.d.ts +15 -0
- package/dist/vue2.mjs +0 -0
- package/dist/vue3.d.ts +13 -0
- package/dist/vue3.mjs +0 -0
- package/package.json +85 -0
- package/src/index.test.ts +273 -0
- package/src/index.ts +15 -0
- package/src/plugin.test.ts +812 -0
- package/src/plugin.ts +107 -0
- package/src/router-link.test.ts +830 -0
- package/src/router-link.ts +172 -0
- package/src/router-view.test.ts +840 -0
- package/src/router-view.ts +59 -0
- package/src/run-with-context.test.ts +64 -0
- package/src/use.test.ts +484 -0
- package/src/use.ts +416 -0
- package/src/util.test.ts +760 -0
- package/src/util.ts +85 -0
- package/src/vue2.ts +18 -0
- package/src/vue3.ts +15 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { RouterLinkProps } 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<RouterLinkProps["to"]>;
|
|
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<RouterLinkProps["type"]>;
|
|
69
|
+
default: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use 'type="replace"' instead
|
|
73
|
+
* @example :replace={true} → type="replace"
|
|
74
|
+
*/
|
|
75
|
+
replace: {
|
|
76
|
+
type: PropType<RouterLinkProps["replace"]>;
|
|
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<RouterLinkProps["exact"]>;
|
|
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: PropType<RouterLinkProps["activeClass"]>;
|
|
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<RouterLinkProps["event"]>;
|
|
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: PropType<RouterLinkProps["tag"]>;
|
|
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<RouterLinkProps["layerOptions"]>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Custom navigation handler called before navigation.
|
|
125
|
+
* Receives the event object and the event name that triggered navigation.
|
|
126
|
+
*
|
|
127
|
+
* @Note you need to call `e.preventDefault()` to prevent default browser navigation.
|
|
128
|
+
*/
|
|
129
|
+
beforeNavigate: {
|
|
130
|
+
type: PropType<RouterLinkProps["beforeNavigate"]>;
|
|
131
|
+
};
|
|
132
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
133
|
+
[key: string]: any;
|
|
134
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
135
|
+
/**
|
|
136
|
+
* Target route location to navigate to.
|
|
137
|
+
* Can be a string path or route location object.
|
|
138
|
+
* @example '/home' | { path: '/user', query: { id: '123' } }
|
|
139
|
+
*/
|
|
140
|
+
to: {
|
|
141
|
+
type: PropType<RouterLinkProps["to"]>;
|
|
142
|
+
required: true;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Navigation type for the link.
|
|
146
|
+
* @default 'push'
|
|
147
|
+
* @example 'push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer'
|
|
148
|
+
*/
|
|
149
|
+
type: {
|
|
150
|
+
type: PropType<RouterLinkProps["type"]>;
|
|
151
|
+
default: string;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated Use 'type="replace"' instead
|
|
155
|
+
* @example :replace={true} → type="replace"
|
|
156
|
+
*/
|
|
157
|
+
replace: {
|
|
158
|
+
type: PropType<RouterLinkProps["replace"]>;
|
|
159
|
+
default: boolean;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* How to match the active state.
|
|
163
|
+
* - 'include': Match if current route includes this path
|
|
164
|
+
* - 'exact': Match only if routes are exactly the same
|
|
165
|
+
* - 'route': Match based on route configuration
|
|
166
|
+
* @default 'include'
|
|
167
|
+
*/
|
|
168
|
+
exact: {
|
|
169
|
+
type: PropType<RouterLinkProps["exact"]>;
|
|
170
|
+
default: string;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* CSS class to apply when link is active (route matches).
|
|
174
|
+
* @example 'nav-active' | 'selected'
|
|
175
|
+
*/
|
|
176
|
+
activeClass: {
|
|
177
|
+
type: PropType<RouterLinkProps["activeClass"]>;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Event(s) that trigger navigation. Can be string or array of strings.
|
|
181
|
+
* @default 'click'
|
|
182
|
+
* @example 'click' | ['click', 'mouseenter']
|
|
183
|
+
*/
|
|
184
|
+
event: {
|
|
185
|
+
type: PropType<RouterLinkProps["event"]>;
|
|
186
|
+
default: string;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Custom tag to render instead of 'a'.
|
|
190
|
+
* @default 'a'
|
|
191
|
+
* @example 'button' | 'div' | 'span'
|
|
192
|
+
*/
|
|
193
|
+
tag: {
|
|
194
|
+
type: PropType<RouterLinkProps["tag"]>;
|
|
195
|
+
default: string;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Layer options for layer-based navigation.
|
|
199
|
+
* Only used when type='pushLayer'.
|
|
200
|
+
* @example { zIndex: 1000, autoPush: false, routerOptions: { mode: 'memory' } }
|
|
201
|
+
*/
|
|
202
|
+
layerOptions: {
|
|
203
|
+
type: PropType<RouterLinkProps["layerOptions"]>;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Custom navigation handler called before navigation.
|
|
207
|
+
* Receives the event object and the event name that triggered navigation.
|
|
208
|
+
*
|
|
209
|
+
* @Note you need to call `e.preventDefault()` to prevent default browser navigation.
|
|
210
|
+
*/
|
|
211
|
+
beforeNavigate: {
|
|
212
|
+
type: PropType<RouterLinkProps["beforeNavigate"]>;
|
|
213
|
+
};
|
|
214
|
+
}>> & Readonly<{}>, {
|
|
215
|
+
type: import("@esmx/router").RouterLinkType | undefined;
|
|
216
|
+
replace: boolean | undefined;
|
|
217
|
+
exact: import("@esmx/router").RouteMatchType | undefined;
|
|
218
|
+
event: string | string[] | undefined;
|
|
219
|
+
tag: string | undefined;
|
|
220
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { defineComponent, h } from "vue";
|
|
2
|
+
import { useLink } from "./use.mjs";
|
|
3
|
+
import { isVue2 } from "./util.mjs";
|
|
4
|
+
export const RouterLink = defineComponent({
|
|
5
|
+
name: "RouterLink",
|
|
6
|
+
props: {
|
|
7
|
+
/**
|
|
8
|
+
* Target route location to navigate to.
|
|
9
|
+
* Can be a string path or route location object.
|
|
10
|
+
* @example '/home' | { path: '/user', query: { id: '123' } }
|
|
11
|
+
*/
|
|
12
|
+
to: {
|
|
13
|
+
type: [String, Object],
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* Navigation type for the link.
|
|
18
|
+
* @default 'push'
|
|
19
|
+
* @example 'push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer'
|
|
20
|
+
*/
|
|
21
|
+
type: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: "push"
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use 'type="replace"' instead
|
|
27
|
+
* @example :replace={true} → type="replace"
|
|
28
|
+
*/
|
|
29
|
+
replace: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
default: false
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* How to match the active state.
|
|
35
|
+
* - 'include': Match if current route includes this path
|
|
36
|
+
* - 'exact': Match only if routes are exactly the same
|
|
37
|
+
* - 'route': Match based on route configuration
|
|
38
|
+
* @default 'include'
|
|
39
|
+
*/
|
|
40
|
+
exact: {
|
|
41
|
+
type: String,
|
|
42
|
+
default: "include"
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* CSS class to apply when link is active (route matches).
|
|
46
|
+
* @example 'nav-active' | 'selected'
|
|
47
|
+
*/
|
|
48
|
+
activeClass: {
|
|
49
|
+
type: String
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Event(s) that trigger navigation. Can be string or array of strings.
|
|
53
|
+
* @default 'click'
|
|
54
|
+
* @example 'click' | ['click', 'mouseenter']
|
|
55
|
+
*/
|
|
56
|
+
event: {
|
|
57
|
+
type: [String, Array],
|
|
58
|
+
default: "click"
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Custom tag to render instead of 'a'.
|
|
62
|
+
* @default 'a'
|
|
63
|
+
* @example 'button' | 'div' | 'span'
|
|
64
|
+
*/
|
|
65
|
+
tag: { type: String, default: "a" },
|
|
66
|
+
/**
|
|
67
|
+
* Layer options for layer-based navigation.
|
|
68
|
+
* Only used when type='pushLayer'.
|
|
69
|
+
* @example { zIndex: 1000, autoPush: false, routerOptions: { mode: 'memory' } }
|
|
70
|
+
*/
|
|
71
|
+
layerOptions: {
|
|
72
|
+
type: Object
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Custom navigation handler called before navigation.
|
|
76
|
+
* Receives the event object and the event name that triggered navigation.
|
|
77
|
+
*
|
|
78
|
+
* @Note you need to call `e.preventDefault()` to prevent default browser navigation.
|
|
79
|
+
*/
|
|
80
|
+
beforeNavigate: {
|
|
81
|
+
type: Function
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
setup(props, context) {
|
|
85
|
+
const link = useLink(props);
|
|
86
|
+
if (isVue2) {
|
|
87
|
+
return () => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const { class: className, ...attributes } = link.value.attributes;
|
|
90
|
+
return h(
|
|
91
|
+
link.value.tag,
|
|
92
|
+
{
|
|
93
|
+
attrs: {
|
|
94
|
+
...attributes,
|
|
95
|
+
...context.attrs
|
|
96
|
+
},
|
|
97
|
+
class: className,
|
|
98
|
+
on: link.value.createEventHandlers()
|
|
99
|
+
},
|
|
100
|
+
(_b = (_a = context.slots).default) == null ? void 0 : _b.call(_a)
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return () => {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
return h(
|
|
107
|
+
link.value.tag,
|
|
108
|
+
{
|
|
109
|
+
...link.value.attributes,
|
|
110
|
+
...context.attrs,
|
|
111
|
+
...link.value.createEventHandlers(
|
|
112
|
+
(name) => "on".concat(name.charAt(0).toUpperCase()).concat(name.slice(1))
|
|
113
|
+
)
|
|
114
|
+
},
|
|
115
|
+
(_b = (_a = context.slots).default) == null ? void 0 : _b.call(_a)
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|