kdu-router 3.1.3 → 3.4.0-beta.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 +9 -56
- package/dist/kdu-router.common.js +3040 -2881
- package/dist/kdu-router.esm.browser.js +3005 -2831
- package/dist/kdu-router.esm.browser.min.js +11 -6
- package/dist/kdu-router.esm.js +3038 -2879
- package/dist/kdu-router.js +3046 -2887
- package/dist/kdu-router.min.js +11 -6
- package/ketur/attributes.json +38 -0
- package/ketur/tags.json +20 -0
- package/package.json +111 -107
- package/src/components/link.js +197 -0
- package/src/components/view.js +149 -0
- package/src/create-matcher.js +200 -200
- package/src/create-route-map.js +205 -205
- package/src/history/abstract.js +68 -0
- package/src/history/base.js +400 -0
- package/src/history/hash.js +163 -0
- package/src/history/html5.js +94 -0
- package/src/index.js +277 -261
- package/src/install.js +52 -52
- package/src/util/async.js +18 -0
- package/src/util/dom.js +3 -0
- package/src/util/errors.js +85 -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 +96 -0
- package/src/util/resolve-components.js +109 -0
- package/src/util/route.js +132 -0
- package/src/util/scroll.js +165 -0
- package/src/util/state-key.js +22 -0
- package/src/util/warn.js +14 -0
- package/types/index.d.ts +17 -16
- package/types/kdu.d.ts +22 -22
- package/types/router.d.ts +170 -145
package/src/index.js
CHANGED
|
@@ -1,261 +1,277 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import { install } from './install'
|
|
4
|
-
import { START } from './util/route'
|
|
5
|
-
import { assert } from './util/warn'
|
|
6
|
-
import { inBrowser } from './util/dom'
|
|
7
|
-
import { cleanPath } from './util/path'
|
|
8
|
-
import { createMatcher } from './create-matcher'
|
|
9
|
-
import { normalizeLocation } from './util/location'
|
|
10
|
-
import { supportsPushState } from './util/push-state'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
case '
|
|
62
|
-
this.history = new
|
|
63
|
-
break
|
|
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
|
-
app
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
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
|
-
this.
|
|
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
|
-
route
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
import { install } from './install'
|
|
4
|
+
import { START } from './util/route'
|
|
5
|
+
import { assert } from './util/warn'
|
|
6
|
+
import { inBrowser } from './util/dom'
|
|
7
|
+
import { cleanPath } from './util/path'
|
|
8
|
+
import { createMatcher } from './create-matcher'
|
|
9
|
+
import { normalizeLocation } from './util/location'
|
|
10
|
+
import { supportsPushState } from './util/push-state'
|
|
11
|
+
import { handleScroll } from './util/scroll'
|
|
12
|
+
|
|
13
|
+
import { HashHistory } from './history/hash'
|
|
14
|
+
import { HTML5History } from './history/html5'
|
|
15
|
+
import { AbstractHistory } from './history/abstract'
|
|
16
|
+
|
|
17
|
+
import type { Matcher } from './create-matcher'
|
|
18
|
+
|
|
19
|
+
import { isNavigationFailure, NavigationFailureType } from './util/errors'
|
|
20
|
+
|
|
21
|
+
export default class KduRouter {
|
|
22
|
+
static install: () => void
|
|
23
|
+
static version: string
|
|
24
|
+
static isNavigationFailure: Function
|
|
25
|
+
static NavigationFailureType: any
|
|
26
|
+
|
|
27
|
+
app: any
|
|
28
|
+
apps: Array<any>
|
|
29
|
+
ready: boolean
|
|
30
|
+
readyCbs: Array<Function>
|
|
31
|
+
options: RouterOptions
|
|
32
|
+
mode: string
|
|
33
|
+
history: HashHistory | HTML5History | AbstractHistory
|
|
34
|
+
matcher: Matcher
|
|
35
|
+
fallback: boolean
|
|
36
|
+
beforeHooks: Array<?NavigationGuard>
|
|
37
|
+
resolveHooks: Array<?NavigationGuard>
|
|
38
|
+
afterHooks: Array<?AfterNavigationHook>
|
|
39
|
+
|
|
40
|
+
constructor (options: RouterOptions = {}) {
|
|
41
|
+
this.app = null
|
|
42
|
+
this.apps = []
|
|
43
|
+
this.options = options
|
|
44
|
+
this.beforeHooks = []
|
|
45
|
+
this.resolveHooks = []
|
|
46
|
+
this.afterHooks = []
|
|
47
|
+
this.matcher = createMatcher(options.routes || [], this)
|
|
48
|
+
|
|
49
|
+
let mode = options.mode || 'hash'
|
|
50
|
+
this.fallback =
|
|
51
|
+
mode === 'history' && !supportsPushState && options.fallback !== false
|
|
52
|
+
if (this.fallback) {
|
|
53
|
+
mode = 'hash'
|
|
54
|
+
}
|
|
55
|
+
if (!inBrowser) {
|
|
56
|
+
mode = 'abstract'
|
|
57
|
+
}
|
|
58
|
+
this.mode = mode
|
|
59
|
+
|
|
60
|
+
switch (mode) {
|
|
61
|
+
case 'history':
|
|
62
|
+
this.history = new HTML5History(this, options.base)
|
|
63
|
+
break
|
|
64
|
+
case 'hash':
|
|
65
|
+
this.history = new HashHistory(this, options.base, this.fallback)
|
|
66
|
+
break
|
|
67
|
+
case 'abstract':
|
|
68
|
+
this.history = new AbstractHistory(this, options.base)
|
|
69
|
+
break
|
|
70
|
+
default:
|
|
71
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
72
|
+
assert(false, `invalid mode: ${mode}`)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
match (raw: RawLocation, current?: Route, redirectedFrom?: Location): Route {
|
|
78
|
+
return this.matcher.match(raw, current, redirectedFrom)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get currentRoute (): ?Route {
|
|
82
|
+
return this.history && this.history.current
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
init (app: any /* Kdu component instance */) {
|
|
86
|
+
process.env.NODE_ENV !== 'production' &&
|
|
87
|
+
assert(
|
|
88
|
+
install.installed,
|
|
89
|
+
`not installed. Make sure to call \`Kdu.use(KduRouter)\` ` +
|
|
90
|
+
`before creating root instance.`
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
this.apps.push(app)
|
|
94
|
+
|
|
95
|
+
// set up app destroyed handler
|
|
96
|
+
app.$once('hook:destroyed', () => {
|
|
97
|
+
// clean out app from this.apps array once destroyed
|
|
98
|
+
const index = this.apps.indexOf(app)
|
|
99
|
+
if (index > -1) this.apps.splice(index, 1)
|
|
100
|
+
// ensure we still have a main app or null if no apps
|
|
101
|
+
// we do not release the router so it can be reused
|
|
102
|
+
if (this.app === app) this.app = this.apps[0] || null
|
|
103
|
+
|
|
104
|
+
if (!this.app) {
|
|
105
|
+
// clean up event listeners
|
|
106
|
+
this.history.teardownListeners()
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// main app previously initialized
|
|
111
|
+
// return as we don't need to set up new history listener
|
|
112
|
+
if (this.app) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.app = app
|
|
117
|
+
|
|
118
|
+
const history = this.history
|
|
119
|
+
|
|
120
|
+
if (history instanceof HTML5History || history instanceof HashHistory) {
|
|
121
|
+
const handleInitialScroll = routeOrError => {
|
|
122
|
+
const from = history.current
|
|
123
|
+
const expectScroll = this.options.scrollBehavior
|
|
124
|
+
const supportsScroll = supportsPushState && expectScroll
|
|
125
|
+
|
|
126
|
+
if (supportsScroll && 'fullPath' in routeOrError) {
|
|
127
|
+
handleScroll(this, routeOrError, from, false)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const setupListeners = routeOrError => {
|
|
131
|
+
history.setupListeners()
|
|
132
|
+
handleInitialScroll(routeOrError)
|
|
133
|
+
}
|
|
134
|
+
history.transitionTo(
|
|
135
|
+
history.getCurrentLocation(),
|
|
136
|
+
setupListeners,
|
|
137
|
+
setupListeners
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
history.listen(route => {
|
|
142
|
+
this.apps.forEach(app => {
|
|
143
|
+
app._route = route
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
beforeEach (fn: Function): Function {
|
|
149
|
+
return registerHook(this.beforeHooks, fn)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
beforeResolve (fn: Function): Function {
|
|
153
|
+
return registerHook(this.resolveHooks, fn)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
afterEach (fn: Function): Function {
|
|
157
|
+
return registerHook(this.afterHooks, fn)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
onReady (cb: Function, errorCb?: Function) {
|
|
161
|
+
this.history.onReady(cb, errorCb)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
onError (errorCb: Function) {
|
|
165
|
+
this.history.onError(errorCb)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
push (location: RawLocation, onComplete?: Function, onAbort?: Function) {
|
|
169
|
+
// $flow-disable-line
|
|
170
|
+
if (!onComplete && !onAbort && typeof Promise !== 'undefined') {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
this.history.push(location, resolve, reject)
|
|
173
|
+
})
|
|
174
|
+
} else {
|
|
175
|
+
this.history.push(location, onComplete, onAbort)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
replace (location: RawLocation, onComplete?: Function, onAbort?: Function) {
|
|
180
|
+
// $flow-disable-line
|
|
181
|
+
if (!onComplete && !onAbort && typeof Promise !== 'undefined') {
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
this.history.replace(location, resolve, reject)
|
|
184
|
+
})
|
|
185
|
+
} else {
|
|
186
|
+
this.history.replace(location, onComplete, onAbort)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
go (n: number) {
|
|
191
|
+
this.history.go(n)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
back () {
|
|
195
|
+
this.go(-1)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
forward () {
|
|
199
|
+
this.go(1)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
getMatchedComponents (to?: RawLocation | Route): Array<any> {
|
|
203
|
+
const route: any = to
|
|
204
|
+
? to.matched
|
|
205
|
+
? to
|
|
206
|
+
: this.resolve(to).route
|
|
207
|
+
: this.currentRoute
|
|
208
|
+
if (!route) {
|
|
209
|
+
return []
|
|
210
|
+
}
|
|
211
|
+
return [].concat.apply(
|
|
212
|
+
[],
|
|
213
|
+
route.matched.map(m => {
|
|
214
|
+
return Object.keys(m.components).map(key => {
|
|
215
|
+
return m.components[key]
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
resolve (
|
|
222
|
+
to: RawLocation,
|
|
223
|
+
current?: Route,
|
|
224
|
+
append?: boolean
|
|
225
|
+
): {
|
|
226
|
+
location: Location,
|
|
227
|
+
route: Route,
|
|
228
|
+
href: string,
|
|
229
|
+
// for backwards compat
|
|
230
|
+
normalizedTo: Location,
|
|
231
|
+
resolved: Route
|
|
232
|
+
} {
|
|
233
|
+
current = current || this.history.current
|
|
234
|
+
const location = normalizeLocation(to, current, append, this)
|
|
235
|
+
const route = this.match(location, current)
|
|
236
|
+
const fullPath = route.redirectedFrom || route.fullPath
|
|
237
|
+
const base = this.history.base
|
|
238
|
+
const href = createHref(base, fullPath, this.mode)
|
|
239
|
+
return {
|
|
240
|
+
location,
|
|
241
|
+
route,
|
|
242
|
+
href,
|
|
243
|
+
// for backwards compat
|
|
244
|
+
normalizedTo: location,
|
|
245
|
+
resolved: route
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
addRoutes (routes: Array<RouteConfig>) {
|
|
250
|
+
this.matcher.addRoutes(routes)
|
|
251
|
+
if (this.history.current !== START) {
|
|
252
|
+
this.history.transitionTo(this.history.getCurrentLocation())
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function registerHook (list: Array<any>, fn: Function): Function {
|
|
258
|
+
list.push(fn)
|
|
259
|
+
return () => {
|
|
260
|
+
const i = list.indexOf(fn)
|
|
261
|
+
if (i > -1) list.splice(i, 1)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function createHref (base: string, fullPath: string, mode) {
|
|
266
|
+
var path = mode === 'hash' ? '#' + fullPath : fullPath
|
|
267
|
+
return base ? cleanPath(base + '/' + path) : path
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
KduRouter.install = install
|
|
271
|
+
KduRouter.version = '__VERSION__'
|
|
272
|
+
KduRouter.isNavigationFailure = isNavigationFailure
|
|
273
|
+
KduRouter.NavigationFailureType = NavigationFailureType
|
|
274
|
+
|
|
275
|
+
if (inBrowser && window.Kdu) {
|
|
276
|
+
window.Kdu.use(KduRouter)
|
|
277
|
+
}
|
package/src/install.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import View from './components/view'
|
|
2
|
-
import Link from './components/link'
|
|
3
|
-
|
|
4
|
-
export let _Kdu
|
|
5
|
-
|
|
6
|
-
export function install (Kdu) {
|
|
7
|
-
if (install.installed && _Kdu === Kdu) return
|
|
8
|
-
install.installed = true
|
|
9
|
-
|
|
10
|
-
_Kdu = Kdu
|
|
11
|
-
|
|
12
|
-
const isDef = v => v !== undefined
|
|
13
|
-
|
|
14
|
-
const registerInstance = (vm, callVal) => {
|
|
15
|
-
let i = vm.$options.
|
|
16
|
-
if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) {
|
|
17
|
-
i(vm, callVal)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
Kdu.mixin({
|
|
22
|
-
beforeCreate () {
|
|
23
|
-
if (isDef(this.$options.router)) {
|
|
24
|
-
this._routerRoot = this
|
|
25
|
-
this._router = this.$options.router
|
|
26
|
-
this._router.init(this)
|
|
27
|
-
Kdu.util.defineReactive(this, '_route', this._router.history.current)
|
|
28
|
-
} else {
|
|
29
|
-
this._routerRoot = (this.$parent && this.$parent._routerRoot) || this
|
|
30
|
-
}
|
|
31
|
-
registerInstance(this, this)
|
|
32
|
-
},
|
|
33
|
-
destroyed () {
|
|
34
|
-
registerInstance(this)
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
Object.defineProperty(Kdu.prototype, '$router', {
|
|
39
|
-
get () { return this._routerRoot._router }
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
Object.defineProperty(Kdu.prototype, '$route', {
|
|
43
|
-
get () { return this._routerRoot._route }
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
Kdu.component('RouterView', View)
|
|
47
|
-
Kdu.component('RouterLink', Link)
|
|
48
|
-
|
|
49
|
-
const strats = Kdu.config.optionMergeStrategies
|
|
50
|
-
// use the same hook merging strategy for route hooks
|
|
51
|
-
strats.beforeRouteEnter = strats.beforeRouteLeave = strats.beforeRouteUpdate = strats.created
|
|
52
|
-
}
|
|
1
|
+
import View from './components/view'
|
|
2
|
+
import Link from './components/link'
|
|
3
|
+
|
|
4
|
+
export let _Kdu
|
|
5
|
+
|
|
6
|
+
export function install (Kdu) {
|
|
7
|
+
if (install.installed && _Kdu === Kdu) return
|
|
8
|
+
install.installed = true
|
|
9
|
+
|
|
10
|
+
_Kdu = Kdu
|
|
11
|
+
|
|
12
|
+
const isDef = v => v !== undefined
|
|
13
|
+
|
|
14
|
+
const registerInstance = (vm, callVal) => {
|
|
15
|
+
let i = vm.$options._parentKnode
|
|
16
|
+
if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) {
|
|
17
|
+
i(vm, callVal)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Kdu.mixin({
|
|
22
|
+
beforeCreate () {
|
|
23
|
+
if (isDef(this.$options.router)) {
|
|
24
|
+
this._routerRoot = this
|
|
25
|
+
this._router = this.$options.router
|
|
26
|
+
this._router.init(this)
|
|
27
|
+
Kdu.util.defineReactive(this, '_route', this._router.history.current)
|
|
28
|
+
} else {
|
|
29
|
+
this._routerRoot = (this.$parent && this.$parent._routerRoot) || this
|
|
30
|
+
}
|
|
31
|
+
registerInstance(this, this)
|
|
32
|
+
},
|
|
33
|
+
destroyed () {
|
|
34
|
+
registerInstance(this)
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
Object.defineProperty(Kdu.prototype, '$router', {
|
|
39
|
+
get () { return this._routerRoot._router }
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
Object.defineProperty(Kdu.prototype, '$route', {
|
|
43
|
+
get () { return this._routerRoot._route }
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
Kdu.component('RouterView', View)
|
|
47
|
+
Kdu.component('RouterLink', Link)
|
|
48
|
+
|
|
49
|
+
const strats = Kdu.config.optionMergeStrategies
|
|
50
|
+
// use the same hook merging strategy for route hooks
|
|
51
|
+
strats.beforeRouteEnter = strats.beforeRouteLeave = strats.beforeRouteUpdate = strats.created
|
|
52
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
export function runQueue (queue: Array<?NavigationGuard>, fn: Function, cb: Function) {
|
|
4
|
+
const step = index => {
|
|
5
|
+
if (index >= queue.length) {
|
|
6
|
+
cb()
|
|
7
|
+
} else {
|
|
8
|
+
if (queue[index]) {
|
|
9
|
+
fn(queue[index], () => {
|
|
10
|
+
step(index + 1)
|
|
11
|
+
})
|
|
12
|
+
} else {
|
|
13
|
+
step(index + 1)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
step(0)
|
|
18
|
+
}
|