kdu-router 3.0.7 → 3.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kdu-router.common.js +729 -486
- package/dist/kdu-router.esm.browser.js +712 -477
- package/dist/kdu-router.esm.browser.min.js +3 -3
- package/dist/kdu-router.esm.js +729 -486
- package/dist/kdu-router.js +2591 -2348
- package/dist/kdu-router.min.js +3 -3
- package/package.json +8 -8
- package/src/components/link.js +190 -0
- package/src/components/view.js +149 -0
- package/src/create-route-map.js +69 -35
- package/src/history/abstract.js +69 -0
- package/src/history/base.js +352 -0
- package/src/history/errors.js +22 -0
- package/src/history/hash.js +154 -0
- package/src/history/html5.js +80 -0
- package/src/index.js +16 -2
- package/src/util/async.js +18 -0
- package/src/util/dom.js +3 -0
- package/src/util/location.js +69 -0
- package/src/util/misc.js +6 -0
- package/src/util/params.js +37 -0
- package/src/util/path.js +74 -0
- package/src/util/push-state.js +46 -0
- package/src/util/query.js +95 -0
- package/src/util/resolve-components.js +108 -0
- package/src/util/route.js +132 -0
- package/src/util/scroll.js +156 -0
- package/src/util/state-key.js +22 -0
- package/src/util/warn.js +25 -0
- package/types/index.d.ts +4 -4
- package/types/kdu.d.ts +10 -10
- package/types/router.d.ts +104 -86
package/types/router.d.ts
CHANGED
|
@@ -1,127 +1,145 @@
|
|
|
1
|
-
import Kdu, { ComponentOptions, PluginFunction, AsyncComponent } from
|
|
1
|
+
import Kdu, { ComponentOptions, PluginFunction, AsyncComponent } from 'kdu'
|
|
2
2
|
|
|
3
|
-
type Component = ComponentOptions<Kdu> | typeof Kdu | AsyncComponent
|
|
4
|
-
type Dictionary<T> = { [key: string]: T }
|
|
5
|
-
type ErrorHandler = (err: Error) => void
|
|
3
|
+
type Component = ComponentOptions<Kdu> | typeof Kdu | AsyncComponent
|
|
4
|
+
type Dictionary < T > = { [key: string]: T }
|
|
5
|
+
type ErrorHandler = (err: Error) => void
|
|
6
6
|
|
|
7
|
-
export type RouterMode =
|
|
8
|
-
export type RawLocation = string | Location
|
|
9
|
-
export type RedirectOption = RawLocation | ((to: Route) => RawLocation)
|
|
10
|
-
export type NavigationGuard<V extends Kdu = Kdu> = (
|
|
7
|
+
export type RouterMode = 'hash' | 'history' | 'abstract'
|
|
8
|
+
export type RawLocation = string | Location
|
|
9
|
+
export type RedirectOption = RawLocation | ((to: Route) => RawLocation)
|
|
10
|
+
export type NavigationGuard < V extends Kdu = Kdu > = (
|
|
11
11
|
to: Route,
|
|
12
12
|
from: Route,
|
|
13
13
|
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void
|
|
14
14
|
) => any
|
|
15
15
|
|
|
16
16
|
export declare class KduRouter {
|
|
17
|
-
constructor
|
|
17
|
+
constructor(options?: RouterOptions)
|
|
18
18
|
|
|
19
|
-
app: Kdu
|
|
20
|
-
mode: RouterMode
|
|
21
|
-
currentRoute: Route
|
|
19
|
+
app: Kdu
|
|
20
|
+
mode: RouterMode
|
|
21
|
+
currentRoute: Route
|
|
22
22
|
|
|
23
|
-
beforeEach
|
|
24
|
-
beforeResolve
|
|
25
|
-
afterEach
|
|
26
|
-
push
|
|
27
|
-
replace
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
beforeEach(guard: NavigationGuard): Function
|
|
24
|
+
beforeResolve(guard: NavigationGuard): Function
|
|
25
|
+
afterEach(hook: (to: Route, from: Route) => any): Function
|
|
26
|
+
push(location: RawLocation): Promise<Route>
|
|
27
|
+
replace(location: RawLocation): Promise<Route>
|
|
28
|
+
push(
|
|
29
|
+
location: RawLocation,
|
|
30
|
+
onComplete?: Function,
|
|
31
|
+
onAbort?: ErrorHandler
|
|
32
|
+
): void
|
|
33
|
+
replace(
|
|
34
|
+
location: RawLocation,
|
|
35
|
+
onComplete?: Function,
|
|
36
|
+
onAbort?: ErrorHandler
|
|
37
|
+
): void
|
|
38
|
+
go(n: number): void
|
|
39
|
+
back(): void
|
|
40
|
+
forward(): void
|
|
41
|
+
getMatchedComponents(to?: RawLocation | Route): Component[]
|
|
42
|
+
onReady(cb: Function, errorCb?: ErrorHandler): void
|
|
43
|
+
onError(cb: ErrorHandler): void
|
|
44
|
+
addRoutes(routes: RouteConfig[]): void
|
|
45
|
+
resolve(
|
|
46
|
+
to: RawLocation,
|
|
47
|
+
current?: Route,
|
|
48
|
+
append?: boolean
|
|
49
|
+
): {
|
|
50
|
+
location: Location
|
|
51
|
+
route: Route
|
|
52
|
+
href: string
|
|
39
53
|
// backwards compat
|
|
40
|
-
normalizedTo: Location
|
|
41
|
-
resolved: Route
|
|
42
|
-
}
|
|
54
|
+
normalizedTo: Location
|
|
55
|
+
resolved: Route
|
|
56
|
+
}
|
|
43
57
|
|
|
44
|
-
static install: PluginFunction<never
|
|
58
|
+
static install: PluginFunction<never>
|
|
45
59
|
}
|
|
46
60
|
|
|
47
|
-
type Position = { x: number
|
|
48
|
-
type PositionResult = Position | { selector: string
|
|
61
|
+
type Position = { x: number; y: number }
|
|
62
|
+
type PositionResult = Position | { selector: string; offset?: Position } | void
|
|
49
63
|
|
|
50
64
|
export interface RouterOptions {
|
|
51
|
-
routes?: RouteConfig[]
|
|
52
|
-
mode?: RouterMode
|
|
53
|
-
fallback?: boolean
|
|
54
|
-
base?: string
|
|
55
|
-
linkActiveClass?: string
|
|
56
|
-
linkExactActiveClass?: string
|
|
57
|
-
parseQuery?: (query: string) => Object
|
|
58
|
-
stringifyQuery?: (query: Object) => string
|
|
65
|
+
routes?: RouteConfig[]
|
|
66
|
+
mode?: RouterMode
|
|
67
|
+
fallback?: boolean
|
|
68
|
+
base?: string
|
|
69
|
+
linkActiveClass?: string
|
|
70
|
+
linkExactActiveClass?: string
|
|
71
|
+
parseQuery?: (query: string) => Object
|
|
72
|
+
stringifyQuery?: (query: Object) => string
|
|
59
73
|
scrollBehavior?: (
|
|
60
74
|
to: Route,
|
|
61
75
|
from: Route,
|
|
62
76
|
savedPosition: Position | void
|
|
63
|
-
) => PositionResult | Promise<PositionResult
|
|
77
|
+
) => PositionResult | Promise<PositionResult> | undefined | null
|
|
64
78
|
}
|
|
65
79
|
|
|
66
|
-
type RoutePropsFunction = (route: Route) => Object
|
|
80
|
+
type RoutePropsFunction = (route: Route) => Object
|
|
67
81
|
|
|
68
82
|
export interface PathToRegexpOptions {
|
|
69
|
-
sensitive?: boolean
|
|
70
|
-
strict?: boolean
|
|
71
|
-
end?: boolean
|
|
83
|
+
sensitive?: boolean
|
|
84
|
+
strict?: boolean
|
|
85
|
+
end?: boolean
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
export interface RouteConfig {
|
|
75
|
-
path: string
|
|
76
|
-
name?: string
|
|
77
|
-
component?: Component
|
|
78
|
-
components?: Dictionary<Component
|
|
79
|
-
redirect?: RedirectOption
|
|
80
|
-
alias?: string | string[]
|
|
81
|
-
children?: RouteConfig[]
|
|
82
|
-
meta?: any
|
|
83
|
-
beforeEnter?: NavigationGuard
|
|
84
|
-
props?: boolean | Object | RoutePropsFunction
|
|
85
|
-
caseSensitive?: boolean
|
|
86
|
-
pathToRegexpOptions?: PathToRegexpOptions
|
|
89
|
+
path: string
|
|
90
|
+
name?: string
|
|
91
|
+
component?: Component
|
|
92
|
+
components?: Dictionary<Component>
|
|
93
|
+
redirect?: RedirectOption
|
|
94
|
+
alias?: string | string[]
|
|
95
|
+
children?: RouteConfig[]
|
|
96
|
+
meta?: any
|
|
97
|
+
beforeEnter?: NavigationGuard
|
|
98
|
+
props?: boolean | Object | RoutePropsFunction
|
|
99
|
+
caseSensitive?: boolean
|
|
100
|
+
pathToRegexpOptions?: PathToRegexpOptions
|
|
87
101
|
}
|
|
88
102
|
|
|
89
103
|
export interface RouteRecord {
|
|
90
|
-
path: string
|
|
91
|
-
regex: RegExp
|
|
92
|
-
components: Dictionary<Component
|
|
93
|
-
instances: Dictionary<Kdu
|
|
94
|
-
name?: string
|
|
95
|
-
parent?: RouteRecord
|
|
96
|
-
redirect?: RedirectOption
|
|
97
|
-
matchAs?: string
|
|
98
|
-
meta: any
|
|
104
|
+
path: string
|
|
105
|
+
regex: RegExp
|
|
106
|
+
components: Dictionary<Component>
|
|
107
|
+
instances: Dictionary<Kdu>
|
|
108
|
+
name?: string
|
|
109
|
+
parent?: RouteRecord
|
|
110
|
+
redirect?: RedirectOption
|
|
111
|
+
matchAs?: string
|
|
112
|
+
meta: any
|
|
99
113
|
beforeEnter?: (
|
|
100
114
|
route: Route,
|
|
101
115
|
redirect: (location: RawLocation) => void,
|
|
102
116
|
next: () => void
|
|
103
|
-
) => any
|
|
104
|
-
props:
|
|
117
|
+
) => any
|
|
118
|
+
props:
|
|
119
|
+
| boolean
|
|
120
|
+
| Object
|
|
121
|
+
| RoutePropsFunction
|
|
122
|
+
| Dictionary<boolean | Object | RoutePropsFunction>
|
|
105
123
|
}
|
|
106
124
|
|
|
107
125
|
export interface Location {
|
|
108
|
-
name?: string
|
|
109
|
-
path?: string
|
|
110
|
-
hash?: string
|
|
111
|
-
query?: Dictionary<string | (string | null)[] | null | undefined
|
|
112
|
-
params?: Dictionary<string
|
|
113
|
-
append?: boolean
|
|
114
|
-
replace?: boolean
|
|
126
|
+
name?: string
|
|
127
|
+
path?: string
|
|
128
|
+
hash?: string
|
|
129
|
+
query?: Dictionary<string | (string | null)[] | null | undefined>
|
|
130
|
+
params?: Dictionary<string>
|
|
131
|
+
append?: boolean
|
|
132
|
+
replace?: boolean
|
|
115
133
|
}
|
|
116
134
|
|
|
117
135
|
export interface Route {
|
|
118
|
-
path: string
|
|
119
|
-
name?: string
|
|
120
|
-
hash: string
|
|
121
|
-
query: Dictionary<string | (string | null)[]
|
|
122
|
-
params: Dictionary<string
|
|
123
|
-
fullPath: string
|
|
124
|
-
matched: RouteRecord[]
|
|
125
|
-
redirectedFrom?: string
|
|
126
|
-
meta?: any
|
|
136
|
+
path: string
|
|
137
|
+
name?: string | null
|
|
138
|
+
hash: string
|
|
139
|
+
query: Dictionary<string | (string | null)[]>
|
|
140
|
+
params: Dictionary<string>
|
|
141
|
+
fullPath: string
|
|
142
|
+
matched: RouteRecord[]
|
|
143
|
+
redirectedFrom?: string
|
|
144
|
+
meta?: any
|
|
127
145
|
}
|