kdu-router 3.5.4 → 3.6.0
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 -21
- package/README.md +11 -11
- package/dist/composables.js +253 -0
- package/dist/composables.mjs +244 -0
- package/dist/kdu-router.common.js +2668 -2665
- package/dist/kdu-router.esm.browser.js +2676 -2670
- package/dist/kdu-router.esm.browser.min.js +5 -5
- package/dist/kdu-router.esm.js +2680 -2674
- package/dist/kdu-router.js +2675 -2672
- package/dist/kdu-router.min.js +5 -5
- package/ketur/attributes.json +38 -38
- package/ketur/tags.json +20 -20
- package/package.json +115 -90
- package/src/components/link.js +224 -224
- package/src/components/view.js +155 -155
- package/src/composables/globals.js +34 -0
- package/src/composables/guards.js +68 -0
- package/src/composables/index.js +3 -0
- package/src/composables/useLink.js +113 -0
- package/src/composables/utils.js +11 -0
- package/src/create-matcher.js +226 -226
- package/src/create-route-map.js +220 -220
- package/src/entries/cjs.js +3 -0
- package/src/entries/esm.js +12 -0
- package/src/history/abstract.js +72 -72
- package/src/history/base.js +379 -379
- package/src/history/hash.js +152 -152
- package/src/history/html5.js +99 -99
- package/src/index.js +3 -293
- package/src/install.js +52 -52
- package/src/router.js +293 -0
- package/src/util/async.js +18 -18
- package/src/util/dom.js +3 -3
- package/src/util/errors.js +86 -86
- package/src/util/location.js +69 -69
- package/src/util/misc.js +6 -6
- package/src/util/params.js +37 -37
- package/src/util/path.js +74 -74
- package/src/util/push-state.js +46 -46
- package/src/util/query.js +113 -113
- package/src/util/resolve-components.js +109 -109
- package/src/util/route.js +151 -151
- package/src/util/scroll.js +175 -175
- package/src/util/state-key.js +22 -22
- package/src/util/warn.js +14 -14
- package/types/composables.d.ts +53 -0
- package/types/index.d.ts +25 -21
- package/types/kdu.d.ts +22 -22
- package/types/router.d.ts +564 -211
package/types/router.d.ts
CHANGED
|
@@ -1,211 +1,564 @@
|
|
|
1
|
-
import Kdu, { ComponentOptions, PluginFunction, AsyncComponent } from 'kdu'
|
|
2
|
-
|
|
3
|
-
type Component = ComponentOptions<Kdu> | typeof Kdu | AsyncComponent
|
|
4
|
-
type Dictionary<T> = { [key: string]: T }
|
|
5
|
-
type ErrorHandler = (err: Error) => void
|
|
6
|
-
|
|
7
|
-
export type RouterMode = 'hash' | 'history' | 'abstract'
|
|
8
|
-
export type RawLocation = string | Location
|
|
9
|
-
export type RedirectOption = RawLocation | ((to: Route) => RawLocation)
|
|
10
|
-
export type NavigationGuardNext<V extends Kdu = Kdu> = (
|
|
11
|
-
to?: RawLocation | false | ((vm: V) => any) | void
|
|
12
|
-
) => void
|
|
13
|
-
|
|
14
|
-
export type NavigationGuard<V extends Kdu = Kdu> = (
|
|
15
|
-
to: Route,
|
|
16
|
-
from: Route,
|
|
17
|
-
next: NavigationGuardNext<V>
|
|
18
|
-
) => any
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
options
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
1
|
+
import Kdu, { ComponentOptions, PluginFunction, AsyncComponent, KNode } from 'kdu'
|
|
2
|
+
|
|
3
|
+
type Component = ComponentOptions<Kdu> | typeof Kdu | AsyncComponent
|
|
4
|
+
type Dictionary<T> = { [key: string]: T }
|
|
5
|
+
type ErrorHandler = (err: Error) => void
|
|
6
|
+
|
|
7
|
+
export type RouterMode = 'hash' | 'history' | 'abstract'
|
|
8
|
+
export type RawLocation = string | Location
|
|
9
|
+
export type RedirectOption = RawLocation | ((to: Route) => RawLocation)
|
|
10
|
+
export type NavigationGuardNext<V extends Kdu = Kdu> = (
|
|
11
|
+
to?: RawLocation | false | ((vm: V) => any) | void
|
|
12
|
+
) => void
|
|
13
|
+
|
|
14
|
+
export type NavigationGuard<V extends Kdu = Kdu> = (
|
|
15
|
+
to: Route,
|
|
16
|
+
from: Route,
|
|
17
|
+
next: NavigationGuardNext<V>
|
|
18
|
+
) => any
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Router instance.
|
|
22
|
+
*/
|
|
23
|
+
export declare class KduRouter {
|
|
24
|
+
constructor(options?: RouterOptions)
|
|
25
|
+
|
|
26
|
+
app: Kdu
|
|
27
|
+
/**
|
|
28
|
+
* Original options object passed to create the Router
|
|
29
|
+
*/
|
|
30
|
+
options: RouterOptions
|
|
31
|
+
/**
|
|
32
|
+
* Configured mode when creating the Router instance.
|
|
33
|
+
*/
|
|
34
|
+
mode: RouterMode
|
|
35
|
+
/**
|
|
36
|
+
* Current {@link Route}
|
|
37
|
+
*/
|
|
38
|
+
currentRoute: Route
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Add a navigation guard that executes before any navigation.
|
|
42
|
+
*
|
|
43
|
+
* @param guard - navigation guard to add
|
|
44
|
+
* @returns a function that removes the registered guard
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```js
|
|
48
|
+
* router.beforeEach((to, from, next) => {
|
|
49
|
+
* // must call `next`
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
beforeEach(guard: NavigationGuard): () => void
|
|
54
|
+
/**
|
|
55
|
+
* Add a navigation guard that executes before navigation is about to be resolved. At this state all component have
|
|
56
|
+
* been fetched and other navigation guards have been successful.
|
|
57
|
+
*
|
|
58
|
+
* @param guard - navigation guard to add
|
|
59
|
+
* @returns a function that removes the registered guard
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```js
|
|
63
|
+
* router.beforeResolve((to, from, next) => {
|
|
64
|
+
* // must call `next`
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
beforeResolve(guard: NavigationGuard): () => void
|
|
69
|
+
/**
|
|
70
|
+
* Add a navigation hook that is executed after every navigation. Returns a function that removes the registered hook.
|
|
71
|
+
*
|
|
72
|
+
* @param hook - navigation hook to add
|
|
73
|
+
* @returns a function that removes the registered guard
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```js
|
|
77
|
+
* router.afterEach((to, from) => {
|
|
78
|
+
* console.log('after navigation')
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
afterEach(hook: (to: Route, from: Route) => any): () => void
|
|
83
|
+
/**
|
|
84
|
+
* Programmatically navigate to a new URL by pushing an entry in the history stack.
|
|
85
|
+
*
|
|
86
|
+
* @param to Route location to navigate to
|
|
87
|
+
*/
|
|
88
|
+
push(to: RawLocation): Promise<Route>
|
|
89
|
+
/**
|
|
90
|
+
* Programmatically navigate to a new URL by pushing an entry in the history stack.
|
|
91
|
+
*
|
|
92
|
+
* @param to Route location to navigate to
|
|
93
|
+
* @param onComplete Navigation success callback
|
|
94
|
+
* @param onAbort Navigation aborted callback
|
|
95
|
+
*/
|
|
96
|
+
push(
|
|
97
|
+
to: RawLocation,
|
|
98
|
+
onComplete?: (route: Route) => void,
|
|
99
|
+
onAbort?: ErrorHandler
|
|
100
|
+
): void
|
|
101
|
+
/**
|
|
102
|
+
* Programmatically navigate to a new URL by replacing the current entry in the history stack.
|
|
103
|
+
*
|
|
104
|
+
* @param to Route location to navigate to
|
|
105
|
+
*/
|
|
106
|
+
replace(to: RawLocation): Promise<Route>
|
|
107
|
+
/**
|
|
108
|
+
* Programmatically navigate to a new URL by replacing the current entry in the history stack.
|
|
109
|
+
*
|
|
110
|
+
* @param to Route location to navigate to
|
|
111
|
+
* @param onComplete Navigation success callback
|
|
112
|
+
* @param onAbort Navigation aborted callback
|
|
113
|
+
*/
|
|
114
|
+
replace(
|
|
115
|
+
to: RawLocation,
|
|
116
|
+
onComplete?: (route: Route) => void,
|
|
117
|
+
onAbort?: ErrorHandler
|
|
118
|
+
): void
|
|
119
|
+
/**
|
|
120
|
+
* Allows you to move forward or backward through the history. Calls `history.go()`.
|
|
121
|
+
*
|
|
122
|
+
* @param delta The position in the history to which you want to move, relative to the current page
|
|
123
|
+
*/
|
|
124
|
+
go(n: number): void
|
|
125
|
+
/**
|
|
126
|
+
* Go back in history if possible by calling `history.back()`. Equivalent to `router.go(-1)`.
|
|
127
|
+
*/
|
|
128
|
+
back(): void
|
|
129
|
+
/**
|
|
130
|
+
* Go forward in history if possible by calling `history.forward()`. Equivalent to `router.go(1)`.
|
|
131
|
+
*/
|
|
132
|
+
forward(): void
|
|
133
|
+
match (raw: RawLocation, current?: Route, redirectedFrom?: Location): Route
|
|
134
|
+
getMatchedComponents(to?: RawLocation | Route): Component[]
|
|
135
|
+
/**
|
|
136
|
+
* This method queues a callback to be called when the router has completed the initial navigation, which means it has
|
|
137
|
+
* resolved all async enter hooks and async components that are associated with the initial route.
|
|
138
|
+
*
|
|
139
|
+
* This is useful in server-side rendering to ensure consistent output on both the server and the client.
|
|
140
|
+
* @param cb onReady callback.
|
|
141
|
+
* @param errorCb errorCb will be called when the initial route resolution runs into an error (e.g. failed to resolve
|
|
142
|
+
* an async component).
|
|
143
|
+
*/
|
|
144
|
+
onReady(cb: () => void, errorCb?: ErrorHandler): void
|
|
145
|
+
/**
|
|
146
|
+
* Adds an error handler that is called every time a non caught error happens during navigation. This includes errors
|
|
147
|
+
* thrown synchronously and asynchronously, errors returned or passed to `next` in any navigation guard, and errors
|
|
148
|
+
* occurred when trying to resolve an async component that is required to render a route.
|
|
149
|
+
*
|
|
150
|
+
* @param handler - error handler to register
|
|
151
|
+
*/
|
|
152
|
+
onError(cb: ErrorHandler): void
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated use {@link addRoute | router.addRoute()} instead
|
|
155
|
+
*/
|
|
156
|
+
addRoutes(routes: RouteConfig[]): void
|
|
157
|
+
/**
|
|
158
|
+
* Add a new {@link RouteConfig | route record} as the child of an existing route. If the route has a `name` and there
|
|
159
|
+
* is already an existing one with the same one, it overwrites it.
|
|
160
|
+
*
|
|
161
|
+
* @param parentName - Parent Route Record where `route` should be appended at
|
|
162
|
+
* @param route - Route Record to add
|
|
163
|
+
*/
|
|
164
|
+
addRoute(parentName: string, route: RouteConfig): void
|
|
165
|
+
/**
|
|
166
|
+
* Add a new {@link RouteConfig | route} to the router. If the route has a `name` and there is already an existing one
|
|
167
|
+
* with the same one, it overwrites it.
|
|
168
|
+
* @param route - Route Record to add
|
|
169
|
+
*/
|
|
170
|
+
addRoute(route: RouteConfig): void
|
|
171
|
+
/**
|
|
172
|
+
* Get the list of all the active route records.
|
|
173
|
+
*/
|
|
174
|
+
getRoutes(): RouteRecordPublic[]
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
*
|
|
178
|
+
* @param to Route location
|
|
179
|
+
* @param current current is the current Route by default (most of the time you don't need to change this)
|
|
180
|
+
* @param append allows you to append the path to the `current` route (as with `router-link`)
|
|
181
|
+
*/
|
|
182
|
+
resolve(
|
|
183
|
+
to: RawLocation,
|
|
184
|
+
current?: Route,
|
|
185
|
+
append?: boolean
|
|
186
|
+
): {
|
|
187
|
+
location: Location
|
|
188
|
+
route: Route
|
|
189
|
+
href: string
|
|
190
|
+
/**
|
|
191
|
+
* backwards compat
|
|
192
|
+
*/
|
|
193
|
+
normalizedTo: Location
|
|
194
|
+
/**
|
|
195
|
+
* backwards compat
|
|
196
|
+
*/
|
|
197
|
+
resolved: Route
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
static install: PluginFunction<never>
|
|
203
|
+
static version: string
|
|
204
|
+
|
|
205
|
+
static isNavigationFailure: typeof isNavigationFailure
|
|
206
|
+
static NavigationFailureType: {
|
|
207
|
+
[k in keyof typeof NavigationFailureType]: NavigationFailureType
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static START_LOCATION: Route
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Enumeration with all possible types for navigation failures.
|
|
215
|
+
*
|
|
216
|
+
* Can be passed to {@link isNavigationFailure} to check for specific failures.
|
|
217
|
+
*/
|
|
218
|
+
export enum NavigationFailureType {
|
|
219
|
+
/**
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
222
|
+
redirected = 2,
|
|
223
|
+
/**
|
|
224
|
+
* An aborted navigation is a navigation that failed because a navigation guard returned `false` or called
|
|
225
|
+
* `next(false)`
|
|
226
|
+
*/
|
|
227
|
+
aborted = 4,
|
|
228
|
+
/**
|
|
229
|
+
* A cancelled navigation is a navigation that failed because a more recent navigation finished started (not
|
|
230
|
+
* necessarily finished).
|
|
231
|
+
*/
|
|
232
|
+
cancelled = 8,
|
|
233
|
+
/**
|
|
234
|
+
* A duplicated navigation is a navigation that failed because it was initiated while already being at the exact same
|
|
235
|
+
* location.
|
|
236
|
+
*/
|
|
237
|
+
duplicated = 16
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Extended Error that contains extra information regarding a failed navigation.
|
|
242
|
+
*/
|
|
243
|
+
export interface NavigationFailure extends Error {
|
|
244
|
+
/**
|
|
245
|
+
* Route location we were navigating from
|
|
246
|
+
*/
|
|
247
|
+
from: Route
|
|
248
|
+
/**
|
|
249
|
+
* Route location we were navigating to
|
|
250
|
+
*/
|
|
251
|
+
to: Route
|
|
252
|
+
/**
|
|
253
|
+
* Type of the navigation. One of {@link NavigationFailureType}
|
|
254
|
+
*/
|
|
255
|
+
type: NavigationFailureType.aborted | NavigationFailureType.cancelled | NavigationFailureType.duplicated
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Check if an object is a {@link NavigationFailure}.
|
|
260
|
+
*/
|
|
261
|
+
export declare function isNavigationFailure(error: any, type?: NavigationFailureType): error is NavigationFailure
|
|
262
|
+
|
|
263
|
+
type Position = { x: number; y: number }
|
|
264
|
+
type PositionResult = Position | { selector: string; offset?: Position, behavior?: ScrollBehavior } | void
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Options to initialize a {@link KduRouter} instance.
|
|
269
|
+
*/
|
|
270
|
+
export interface RouterOptions {
|
|
271
|
+
routes?: RouteConfig[]
|
|
272
|
+
/**
|
|
273
|
+
* Configure the router mode.
|
|
274
|
+
*
|
|
275
|
+
* default: `"hash"` (in browser) | `"abstract"` (in Node.js)
|
|
276
|
+
*
|
|
277
|
+
* available values: `"hash" | "history" | "abstract"`
|
|
278
|
+
* - `"hash"`: uses the URL hash for routing. Works in all Kdu-supported browsers, including those that do not support
|
|
279
|
+
* HTML5 History API.
|
|
280
|
+
* - `"history"`: requires HTML5 History API and server config. See HTML5 History Mode.
|
|
281
|
+
* - `"abstract"`: works in all JavaScript environments, e.g. server-side with Node.js. **The router will
|
|
282
|
+
* automatically be forced into this mode if no browser API is present.**
|
|
283
|
+
*/
|
|
284
|
+
mode?: RouterMode
|
|
285
|
+
fallback?: boolean
|
|
286
|
+
base?: string
|
|
287
|
+
/**
|
|
288
|
+
* Default class applied to active {@link RouterLink}. If none is provided, `router-link-active` will be applied.
|
|
289
|
+
*/
|
|
290
|
+
linkActiveClass?: string
|
|
291
|
+
/**
|
|
292
|
+
* Default class applied to active {@link RouterLink}. If none is provided, `router-link-exact-active` will be
|
|
293
|
+
* applied.
|
|
294
|
+
*/
|
|
295
|
+
linkExactActiveClass?: string
|
|
296
|
+
/**
|
|
297
|
+
* Custom implementation to parse a query. See its counterpart, {@link stringifyQuery}.
|
|
298
|
+
*/
|
|
299
|
+
parseQuery?: (query: string) => Object
|
|
300
|
+
/**
|
|
301
|
+
* Custom implementation to stringify a query object. Should not prepend a leading `?`. {@link parseQuery} counterpart
|
|
302
|
+
* to handle query parsing.
|
|
303
|
+
*/
|
|
304
|
+
stringifyQuery?: (query: Object) => string
|
|
305
|
+
/**
|
|
306
|
+
* Function to control scrolling when navigating between pages. Can return a Promise to delay scrolling.
|
|
307
|
+
*
|
|
308
|
+
* For more details see {@link Scroll Behavior}.
|
|
309
|
+
*/
|
|
310
|
+
scrollBehavior?: (
|
|
311
|
+
to: Route,
|
|
312
|
+
from: Route,
|
|
313
|
+
savedPosition: Position | void
|
|
314
|
+
) => PositionResult | Promise<PositionResult> | undefined | null
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
type RoutePropsFunction = (route: Route) => Object
|
|
318
|
+
|
|
319
|
+
export interface PathToRegexpOptions {
|
|
320
|
+
sensitive?: boolean
|
|
321
|
+
strict?: boolean
|
|
322
|
+
end?: boolean
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface _RouteConfigBase {
|
|
326
|
+
path: string
|
|
327
|
+
name?: string
|
|
328
|
+
children?: RouteConfig[]
|
|
329
|
+
redirect?: RedirectOption
|
|
330
|
+
alias?: string | string[]
|
|
331
|
+
meta?: RouteMeta
|
|
332
|
+
beforeEnter?: NavigationGuard
|
|
333
|
+
caseSensitive?: boolean
|
|
334
|
+
pathToRegexpOptions?: PathToRegexpOptions
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
interface RouteConfigSingleView extends _RouteConfigBase {
|
|
338
|
+
component?: Component
|
|
339
|
+
props?: boolean | Object | RoutePropsFunction
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
interface RouteConfigMultipleViews extends _RouteConfigBase {
|
|
343
|
+
components?: Dictionary<Component>
|
|
344
|
+
props?: Dictionary<boolean | Object | RoutePropsFunction>
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews
|
|
348
|
+
|
|
349
|
+
export interface RouteRecord {
|
|
350
|
+
path: string
|
|
351
|
+
regex: RegExp
|
|
352
|
+
components: Dictionary<Component>
|
|
353
|
+
instances: Dictionary<Kdu>
|
|
354
|
+
name?: string
|
|
355
|
+
parent?: RouteRecord
|
|
356
|
+
redirect?: RedirectOption
|
|
357
|
+
matchAs?: string
|
|
358
|
+
meta: RouteMeta
|
|
359
|
+
beforeEnter?: (
|
|
360
|
+
route: Route,
|
|
361
|
+
redirect: (location: RawLocation) => void,
|
|
362
|
+
next: () => void
|
|
363
|
+
) => any
|
|
364
|
+
props:
|
|
365
|
+
| boolean
|
|
366
|
+
| Object
|
|
367
|
+
| RoutePropsFunction
|
|
368
|
+
| Dictionary<boolean | Object | RoutePropsFunction>
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface RouteRecordPublic {
|
|
372
|
+
path: string
|
|
373
|
+
components: Dictionary<Component>
|
|
374
|
+
instances: Dictionary<Kdu>
|
|
375
|
+
name?: string
|
|
376
|
+
redirect?: RedirectOption
|
|
377
|
+
meta: any
|
|
378
|
+
beforeEnter?: (
|
|
379
|
+
route: Route,
|
|
380
|
+
redirect: (location: RawLocation) => void,
|
|
381
|
+
next: () => void
|
|
382
|
+
) => any
|
|
383
|
+
props:
|
|
384
|
+
| boolean
|
|
385
|
+
| Object
|
|
386
|
+
| RoutePropsFunction
|
|
387
|
+
| Dictionary<boolean | Object | RoutePropsFunction>
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
export interface Location {
|
|
392
|
+
name?: string
|
|
393
|
+
path?: string
|
|
394
|
+
hash?: string
|
|
395
|
+
query?: Dictionary<string | (string | null)[] | null | undefined>
|
|
396
|
+
params?: Dictionary<string>
|
|
397
|
+
append?: boolean
|
|
398
|
+
replace?: boolean
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface Route {
|
|
402
|
+
path: string
|
|
403
|
+
name?: string | null
|
|
404
|
+
hash: string
|
|
405
|
+
query: Dictionary<string | (string | null)[]>
|
|
406
|
+
params: Dictionary<string>
|
|
407
|
+
fullPath: string
|
|
408
|
+
matched: RouteRecord[]
|
|
409
|
+
redirectedFrom?: string
|
|
410
|
+
meta?: RouteMeta
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface RouteMeta extends Record<string | number | symbol, any> {}
|
|
414
|
+
|
|
415
|
+
export interface RouterLinkProps {
|
|
416
|
+
/**
|
|
417
|
+
* Denotes the target route of the link. When clicked, the value of the `to` prop will be passed to
|
|
418
|
+
* `router.push()` internally, so the value can be either a string or a location descriptor object.
|
|
419
|
+
*/
|
|
420
|
+
to: string | Location
|
|
421
|
+
/**
|
|
422
|
+
* Setting `replace` prop will call `router.replace()` instead of `router.push()` when clicked, so the navigation will
|
|
423
|
+
* not create a new history record.
|
|
424
|
+
*
|
|
425
|
+
* @default false
|
|
426
|
+
*/
|
|
427
|
+
replace?: boolean
|
|
428
|
+
/**
|
|
429
|
+
* Setting `append` prop always appends the relative path to the current path. For example, assuming we are navigating
|
|
430
|
+
* from `/a` to a relative link `b`, without `append` we will end up at `/b`, but with append we will end up at
|
|
431
|
+
* `/a/b`.
|
|
432
|
+
*
|
|
433
|
+
* @default false
|
|
434
|
+
*/
|
|
435
|
+
append?: boolean
|
|
436
|
+
/**
|
|
437
|
+
* Sometimes we want <RouterLink> to render as another tag, e.g <li>. Then we can use tag prop to specify which tag to
|
|
438
|
+
* render to, and it will still listen to click events for navigation.
|
|
439
|
+
*
|
|
440
|
+
* @default "a"
|
|
441
|
+
*/
|
|
442
|
+
tag?: string
|
|
443
|
+
/**
|
|
444
|
+
* Configure the active CSS class applied when the link is active. Note the default value can also be configured
|
|
445
|
+
* globally via the `linkActiveClass` router constructor option.
|
|
446
|
+
*
|
|
447
|
+
* @default "router-link-active"
|
|
448
|
+
*/
|
|
449
|
+
activeClass?: string
|
|
450
|
+
/**
|
|
451
|
+
* The default active class matching behavior is **inclusive match**. For example, `<RouterLink to="/a">` will get
|
|
452
|
+
* this class applied as long as the current path starts with `/a/` or is `/a`.
|
|
453
|
+
*
|
|
454
|
+
* @default false
|
|
455
|
+
*/
|
|
456
|
+
exact?: boolean
|
|
457
|
+
/**
|
|
458
|
+
* Allows matching only using the `path` section of the url, effectively ignoring the `query` and the `hash` sections.
|
|
459
|
+
*
|
|
460
|
+
* @default false
|
|
461
|
+
*/
|
|
462
|
+
exactPath?: boolean
|
|
463
|
+
/**
|
|
464
|
+
* Configure the active CSS class applied when the link is active with exact path match. Note the default value can
|
|
465
|
+
* also be configured globally via the `linkExactPathActiveClass` router constructor option.
|
|
466
|
+
*
|
|
467
|
+
* @default "router-link-exact-path-active"
|
|
468
|
+
*/
|
|
469
|
+
exactPathActiveClass?: string
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Specify the event(s) that can trigger the link navigation.
|
|
473
|
+
*
|
|
474
|
+
* @default 'click'
|
|
475
|
+
*/
|
|
476
|
+
event?: string | ReadonlyArray<string>
|
|
477
|
+
/**
|
|
478
|
+
* Configure the active CSS class applied when the link is active with exact match. Note the default value can also be
|
|
479
|
+
* configured globally via the `linkExactActiveClass` router constructor option.
|
|
480
|
+
*
|
|
481
|
+
* @default "router-link-exact-active"
|
|
482
|
+
*/
|
|
483
|
+
exactActiveClass?: string
|
|
484
|
+
/**
|
|
485
|
+
* Configure the value of `aria-current` when the link is active with exact match. It must be one of the allowed
|
|
486
|
+
* values for [aria-current](https://www.w3.org/TR/wai-aria-1.2/#aria-current) in the ARIA spec. In most cases, the
|
|
487
|
+
* default of page should be the best fit.
|
|
488
|
+
*
|
|
489
|
+
* @default "page"
|
|
490
|
+
*/
|
|
491
|
+
ariaCurrentValue?:
|
|
492
|
+
| 'page'
|
|
493
|
+
| 'step'
|
|
494
|
+
| 'location'
|
|
495
|
+
| 'date'
|
|
496
|
+
| 'time'
|
|
497
|
+
| 'true'
|
|
498
|
+
| 'false'
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export interface RouterLinkSlotArgument {
|
|
502
|
+
/**
|
|
503
|
+
* resolved url. This would be the `href` attribute of an `a` element
|
|
504
|
+
*/
|
|
505
|
+
href: string
|
|
506
|
+
/**
|
|
507
|
+
* resolved normalized location
|
|
508
|
+
*/
|
|
509
|
+
route: Route
|
|
510
|
+
/**
|
|
511
|
+
* function to trigger the navigation. It will automatically prevent events when necessary, the same way `RouterLink`
|
|
512
|
+
* does
|
|
513
|
+
*/
|
|
514
|
+
navigate: (e?: MouseEvent) => Promise<undefined | NavigationFailure>
|
|
515
|
+
/**
|
|
516
|
+
* `true` if the [active class](https://kdujs-router-v3.web.app/api/#active-class) should be applied. Allows to apply an
|
|
517
|
+
* arbitrary class
|
|
518
|
+
*/
|
|
519
|
+
isActive: boolean
|
|
520
|
+
/**
|
|
521
|
+
* `true` if the [exact active class](https://kdujs-router-v3.web.app/api/#exact-active-class) should be applied. Allows
|
|
522
|
+
* to apply an arbitrary class
|
|
523
|
+
*/
|
|
524
|
+
isExactActive: boolean
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Component to render a link that triggers a navigation on click.
|
|
529
|
+
*/
|
|
530
|
+
export declare const RouterLink: new () => {
|
|
531
|
+
$props: RouterLinkProps
|
|
532
|
+
$scopedSlots: {
|
|
533
|
+
default?: ({
|
|
534
|
+
href,
|
|
535
|
+
route,
|
|
536
|
+
navigate,
|
|
537
|
+
isActive,
|
|
538
|
+
isExactActive
|
|
539
|
+
}: RouterLinkSlotArgument) => KNode[] | undefined
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export interface RouterViewProps {
|
|
544
|
+
/**
|
|
545
|
+
* When a {@link RouterView | `<RouterView />`} has a name, it will render the component with the corresponding name
|
|
546
|
+
* in the matched route record's components option. See [Named
|
|
547
|
+
* Views](https://kdujs-router-v3.web.app/guide/essentials/named-views.html) for an example.
|
|
548
|
+
*
|
|
549
|
+
* @default "default"
|
|
550
|
+
*/
|
|
551
|
+
name?: string
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Component to display the current route the user is at.
|
|
556
|
+
*/
|
|
557
|
+
export declare const RouterView: new () => {
|
|
558
|
+
$props: RouterViewProps
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Initial route location where the router is. Can be used in navigation guards to differentiate the initial navigation.
|
|
563
|
+
*/
|
|
564
|
+
export declare const START_LOCATION: Route
|