kdu-router 3.4.0-beta.0 → 4.0.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.
Files changed (45) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +8 -6
  3. package/dist/kdu-router.cjs.js +2848 -0
  4. package/dist/kdu-router.cjs.prod.js +2610 -0
  5. package/dist/kdu-router.d.ts +1255 -0
  6. package/dist/kdu-router.esm-browser.js +3332 -0
  7. package/dist/kdu-router.esm-bundler.js +3343 -0
  8. package/dist/kdu-router.global.js +3354 -0
  9. package/dist/kdu-router.global.prod.js +6 -0
  10. package/ketur/attributes.json +8 -14
  11. package/ketur/tags.json +2 -12
  12. package/package.json +64 -92
  13. package/dist/kdu-router.common.js +0 -3040
  14. package/dist/kdu-router.esm.browser.js +0 -3005
  15. package/dist/kdu-router.esm.browser.min.js +0 -11
  16. package/dist/kdu-router.esm.js +0 -3038
  17. package/dist/kdu-router.js +0 -3046
  18. package/dist/kdu-router.min.js +0 -11
  19. package/src/components/link.js +0 -197
  20. package/src/components/view.js +0 -149
  21. package/src/create-matcher.js +0 -200
  22. package/src/create-route-map.js +0 -205
  23. package/src/history/abstract.js +0 -68
  24. package/src/history/base.js +0 -400
  25. package/src/history/hash.js +0 -163
  26. package/src/history/html5.js +0 -94
  27. package/src/index.js +0 -277
  28. package/src/install.js +0 -52
  29. package/src/util/async.js +0 -18
  30. package/src/util/dom.js +0 -3
  31. package/src/util/errors.js +0 -85
  32. package/src/util/location.js +0 -69
  33. package/src/util/misc.js +0 -6
  34. package/src/util/params.js +0 -37
  35. package/src/util/path.js +0 -74
  36. package/src/util/push-state.js +0 -46
  37. package/src/util/query.js +0 -96
  38. package/src/util/resolve-components.js +0 -109
  39. package/src/util/route.js +0 -132
  40. package/src/util/scroll.js +0 -165
  41. package/src/util/state-key.js +0 -22
  42. package/src/util/warn.js +0 -14
  43. package/types/index.d.ts +0 -17
  44. package/types/kdu.d.ts +0 -22
  45. package/types/router.d.ts +0 -170
@@ -1,3046 +0,0 @@
1
- /*!
2
- * kdu-router v3.4.0-beta.0
3
- * (c) 2022 NKDuy
4
- * @license MIT
5
- */
6
- (function (global, factory) {
7
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
- typeof define === 'function' && define.amd ? define(factory) :
9
- (global = global || self, global.KduRouter = factory());
10
- }(this, (function () { 'use strict';
11
-
12
- /* */
13
-
14
- function assert (condition, message) {
15
- if (!condition) {
16
- throw new Error(("[kdu-router] " + message))
17
- }
18
- }
19
-
20
- function warn (condition, message) {
21
- if ( !condition) {
22
- typeof console !== 'undefined' && console.warn(("[kdu-router] " + message));
23
- }
24
- }
25
-
26
- function extend (a, b) {
27
- for (var key in b) {
28
- a[key] = b[key];
29
- }
30
- return a
31
- }
32
-
33
- var View = {
34
- name: 'RouterView',
35
- functional: true,
36
- props: {
37
- name: {
38
- type: String,
39
- default: 'default'
40
- }
41
- },
42
- render: function render (_, ref) {
43
- var props = ref.props;
44
- var children = ref.children;
45
- var parent = ref.parent;
46
- var data = ref.data;
47
-
48
- // used by devtools to display a router-view badge
49
- data.routerView = true;
50
-
51
- // directly use parent context's createElement() function
52
- // so that components rendered by router-view can resolve named slots
53
- var h = parent.$createElement;
54
- var name = props.name;
55
- var route = parent.$route;
56
- var cache = parent._routerViewCache || (parent._routerViewCache = {});
57
-
58
- // determine current view depth, also check to see if the tree
59
- // has been toggled inactive but kept-alive.
60
- var depth = 0;
61
- var inactive = false;
62
- while (parent && parent._routerRoot !== parent) {
63
- var knodeData = parent.$knode ? parent.$knode.data : {};
64
- if (knodeData.routerView) {
65
- depth++;
66
- }
67
- if (knodeData.keepAlive && parent._directInactive && parent._inactive) {
68
- inactive = true;
69
- }
70
- parent = parent.$parent;
71
- }
72
- data.routerViewDepth = depth;
73
-
74
- // render previous view if the tree is inactive and kept-alive
75
- if (inactive) {
76
- var cachedData = cache[name];
77
- var cachedComponent = cachedData && cachedData.component;
78
- if (cachedComponent) {
79
- // #2301
80
- // pass props
81
- if (cachedData.configProps) {
82
- fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps);
83
- }
84
- return h(cachedComponent, data, children)
85
- } else {
86
- // render previous empty view
87
- return h()
88
- }
89
- }
90
-
91
- var matched = route.matched[depth];
92
- var component = matched && matched.components[name];
93
-
94
- // render empty node if no matched route or no config component
95
- if (!matched || !component) {
96
- cache[name] = null;
97
- return h()
98
- }
99
-
100
- // cache component
101
- cache[name] = { component: component };
102
-
103
- // attach instance registration hook
104
- // this will be called in the instance's injected lifecycle hooks
105
- data.registerRouteInstance = function (vm, val) {
106
- // val could be undefined for unregistration
107
- var current = matched.instances[name];
108
- if (
109
- (val && current !== vm) ||
110
- (!val && current === vm)
111
- ) {
112
- matched.instances[name] = val;
113
- }
114
- }
115
-
116
- // also register instance in prepatch hook
117
- // in case the same component instance is reused across different routes
118
- ;(data.hook || (data.hook = {})).prepatch = function (_, knode) {
119
- matched.instances[name] = knode.componentInstance;
120
- };
121
-
122
- // register instance in init hook
123
- // in case kept-alive component be actived when routes changed
124
- data.hook.init = function (knode) {
125
- if (knode.data.keepAlive &&
126
- knode.componentInstance &&
127
- knode.componentInstance !== matched.instances[name]
128
- ) {
129
- matched.instances[name] = knode.componentInstance;
130
- }
131
- };
132
-
133
- var configProps = matched.props && matched.props[name];
134
- // save route and configProps in cache
135
- if (configProps) {
136
- extend(cache[name], {
137
- route: route,
138
- configProps: configProps
139
- });
140
- fillPropsinData(component, data, route, configProps);
141
- }
142
-
143
- return h(component, data, children)
144
- }
145
- };
146
-
147
- function fillPropsinData (component, data, route, configProps) {
148
- // resolve props
149
- var propsToPass = data.props = resolveProps(route, configProps);
150
- if (propsToPass) {
151
- // clone to prevent mutation
152
- propsToPass = data.props = extend({}, propsToPass);
153
- // pass non-declared props as attrs
154
- var attrs = data.attrs = data.attrs || {};
155
- for (var key in propsToPass) {
156
- if (!component.props || !(key in component.props)) {
157
- attrs[key] = propsToPass[key];
158
- delete propsToPass[key];
159
- }
160
- }
161
- }
162
- }
163
-
164
- function resolveProps (route, config) {
165
- switch (typeof config) {
166
- case 'undefined':
167
- return
168
- case 'object':
169
- return config
170
- case 'function':
171
- return config(route)
172
- case 'boolean':
173
- return config ? route.params : undefined
174
- default:
175
- {
176
- warn(
177
- false,
178
- "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " +
179
- "expecting an object, function or boolean."
180
- );
181
- }
182
- }
183
- }
184
-
185
- /* */
186
-
187
- var encodeReserveRE = /[!'()*]/g;
188
- var encodeReserveReplacer = function (c) { return '%' + c.charCodeAt(0).toString(16); };
189
- var commaRE = /%2C/g;
190
-
191
- // fixed encodeURIComponent which is more conformant to RFC3986:
192
- // - escapes [!'()*]
193
- // - preserve commas
194
- var encode = function (str) { return encodeURIComponent(str)
195
- .replace(encodeReserveRE, encodeReserveReplacer)
196
- .replace(commaRE, ','); };
197
-
198
- var decode = decodeURIComponent;
199
-
200
- function resolveQuery (
201
- query,
202
- extraQuery,
203
- _parseQuery
204
- ) {
205
- if ( extraQuery === void 0 ) extraQuery = {};
206
-
207
- var parse = _parseQuery || parseQuery;
208
- var parsedQuery;
209
- try {
210
- parsedQuery = parse(query || '');
211
- } catch (e) {
212
- warn(false, e.message);
213
- parsedQuery = {};
214
- }
215
- for (var key in extraQuery) {
216
- var value = extraQuery[key];
217
- parsedQuery[key] = Array.isArray(value) ? value.map(function (v) { return '' + v; }) : '' + value;
218
- }
219
- return parsedQuery
220
- }
221
-
222
- function parseQuery (query) {
223
- var res = {};
224
-
225
- query = query.trim().replace(/^(\?|#|&)/, '');
226
-
227
- if (!query) {
228
- return res
229
- }
230
-
231
- query.split('&').forEach(function (param) {
232
- var parts = param.replace(/\+/g, ' ').split('=');
233
- var key = decode(parts.shift());
234
- var val = parts.length > 0
235
- ? decode(parts.join('='))
236
- : null;
237
-
238
- if (res[key] === undefined) {
239
- res[key] = val;
240
- } else if (Array.isArray(res[key])) {
241
- res[key].push(val);
242
- } else {
243
- res[key] = [res[key], val];
244
- }
245
- });
246
-
247
- return res
248
- }
249
-
250
- function stringifyQuery (obj) {
251
- var res = obj ? Object.keys(obj).map(function (key) {
252
- var val = obj[key];
253
-
254
- if (val === undefined) {
255
- return ''
256
- }
257
-
258
- if (val === null) {
259
- return encode(key)
260
- }
261
-
262
- if (Array.isArray(val)) {
263
- var result = [];
264
- val.forEach(function (val2) {
265
- if (val2 === undefined) {
266
- return
267
- }
268
- if (val2 === null) {
269
- result.push(encode(key));
270
- } else {
271
- result.push(encode(key) + '=' + encode(val2));
272
- }
273
- });
274
- return result.join('&')
275
- }
276
-
277
- return encode(key) + '=' + encode(val)
278
- }).filter(function (x) { return x.length > 0; }).join('&') : null;
279
- return res ? ("?" + res) : ''
280
- }
281
-
282
- /* */
283
-
284
- var trailingSlashRE = /\/?$/;
285
-
286
- function createRoute (
287
- record,
288
- location,
289
- redirectedFrom,
290
- router
291
- ) {
292
- var stringifyQuery = router && router.options.stringifyQuery;
293
-
294
- var query = location.query || {};
295
- try {
296
- query = clone(query);
297
- } catch (e) {}
298
-
299
- var route = {
300
- name: location.name || (record && record.name),
301
- meta: (record && record.meta) || {},
302
- path: location.path || '/',
303
- hash: location.hash || '',
304
- query: query,
305
- params: location.params || {},
306
- fullPath: getFullPath(location, stringifyQuery),
307
- matched: record ? formatMatch(record) : []
308
- };
309
- if (redirectedFrom) {
310
- route.redirectedFrom = getFullPath(redirectedFrom, stringifyQuery);
311
- }
312
- return Object.freeze(route)
313
- }
314
-
315
- function clone (value) {
316
- if (Array.isArray(value)) {
317
- return value.map(clone)
318
- } else if (value && typeof value === 'object') {
319
- var res = {};
320
- for (var key in value) {
321
- res[key] = clone(value[key]);
322
- }
323
- return res
324
- } else {
325
- return value
326
- }
327
- }
328
-
329
- // the starting route that represents the initial state
330
- var START = createRoute(null, {
331
- path: '/'
332
- });
333
-
334
- function formatMatch (record) {
335
- var res = [];
336
- while (record) {
337
- res.unshift(record);
338
- record = record.parent;
339
- }
340
- return res
341
- }
342
-
343
- function getFullPath (
344
- ref,
345
- _stringifyQuery
346
- ) {
347
- var path = ref.path;
348
- var query = ref.query; if ( query === void 0 ) query = {};
349
- var hash = ref.hash; if ( hash === void 0 ) hash = '';
350
-
351
- var stringify = _stringifyQuery || stringifyQuery;
352
- return (path || '/') + stringify(query) + hash
353
- }
354
-
355
- function isSameRoute (a, b) {
356
- if (b === START) {
357
- return a === b
358
- } else if (!b) {
359
- return false
360
- } else if (a.path && b.path) {
361
- return (
362
- a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') &&
363
- a.hash === b.hash &&
364
- isObjectEqual(a.query, b.query)
365
- )
366
- } else if (a.name && b.name) {
367
- return (
368
- a.name === b.name &&
369
- a.hash === b.hash &&
370
- isObjectEqual(a.query, b.query) &&
371
- isObjectEqual(a.params, b.params)
372
- )
373
- } else {
374
- return false
375
- }
376
- }
377
-
378
- function isObjectEqual (a, b) {
379
- if ( a === void 0 ) a = {};
380
- if ( b === void 0 ) b = {};
381
-
382
- // handle null value #1566
383
- if (!a || !b) { return a === b }
384
- var aKeys = Object.keys(a);
385
- var bKeys = Object.keys(b);
386
- if (aKeys.length !== bKeys.length) {
387
- return false
388
- }
389
- return aKeys.every(function (key) {
390
- var aVal = a[key];
391
- var bVal = b[key];
392
- // check nested equality
393
- if (typeof aVal === 'object' && typeof bVal === 'object') {
394
- return isObjectEqual(aVal, bVal)
395
- }
396
- return String(aVal) === String(bVal)
397
- })
398
- }
399
-
400
- function isIncludedRoute (current, target) {
401
- return (
402
- current.path.replace(trailingSlashRE, '/').indexOf(
403
- target.path.replace(trailingSlashRE, '/')
404
- ) === 0 &&
405
- (!target.hash || current.hash === target.hash) &&
406
- queryIncludes(current.query, target.query)
407
- )
408
- }
409
-
410
- function queryIncludes (current, target) {
411
- for (var key in target) {
412
- if (!(key in current)) {
413
- return false
414
- }
415
- }
416
- return true
417
- }
418
-
419
- /* */
420
-
421
- function resolvePath (
422
- relative,
423
- base,
424
- append
425
- ) {
426
- var firstChar = relative.charAt(0);
427
- if (firstChar === '/') {
428
- return relative
429
- }
430
-
431
- if (firstChar === '?' || firstChar === '#') {
432
- return base + relative
433
- }
434
-
435
- var stack = base.split('/');
436
-
437
- // remove trailing segment if:
438
- // - not appending
439
- // - appending to trailing slash (last segment is empty)
440
- if (!append || !stack[stack.length - 1]) {
441
- stack.pop();
442
- }
443
-
444
- // resolve relative path
445
- var segments = relative.replace(/^\//, '').split('/');
446
- for (var i = 0; i < segments.length; i++) {
447
- var segment = segments[i];
448
- if (segment === '..') {
449
- stack.pop();
450
- } else if (segment !== '.') {
451
- stack.push(segment);
452
- }
453
- }
454
-
455
- // ensure leading slash
456
- if (stack[0] !== '') {
457
- stack.unshift('');
458
- }
459
-
460
- return stack.join('/')
461
- }
462
-
463
- function parsePath (path) {
464
- var hash = '';
465
- var query = '';
466
-
467
- var hashIndex = path.indexOf('#');
468
- if (hashIndex >= 0) {
469
- hash = path.slice(hashIndex);
470
- path = path.slice(0, hashIndex);
471
- }
472
-
473
- var queryIndex = path.indexOf('?');
474
- if (queryIndex >= 0) {
475
- query = path.slice(queryIndex + 1);
476
- path = path.slice(0, queryIndex);
477
- }
478
-
479
- return {
480
- path: path,
481
- query: query,
482
- hash: hash
483
- }
484
- }
485
-
486
- function cleanPath (path) {
487
- return path.replace(/\/\//g, '/')
488
- }
489
-
490
- var isarray = Array.isArray || function (arr) {
491
- return Object.prototype.toString.call(arr) == '[object Array]';
492
- };
493
-
494
- /**
495
- * Expose `pathToRegexp`.
496
- */
497
- var pathToRegexp_1 = pathToRegexp;
498
- var parse_1 = parse;
499
- var compile_1 = compile;
500
- var tokensToFunction_1 = tokensToFunction;
501
- var tokensToRegExp_1 = tokensToRegExp;
502
-
503
- /**
504
- * The main path matching regexp utility.
505
- *
506
- * @type {RegExp}
507
- */
508
- var PATH_REGEXP = new RegExp([
509
- // Match escaped characters that would otherwise appear in future matches.
510
- // This allows the user to escape special characters that won't transform.
511
- '(\\\\.)',
512
- // Match Express-style parameters and un-named parameters with a prefix
513
- // and optional suffixes. Matches appear as:
514
- //
515
- // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
516
- // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
517
- // "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
518
- '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
519
- ].join('|'), 'g');
520
-
521
- /**
522
- * Parse a string for the raw tokens.
523
- *
524
- * @param {string} str
525
- * @param {Object=} options
526
- * @return {!Array}
527
- */
528
- function parse (str, options) {
529
- var tokens = [];
530
- var key = 0;
531
- var index = 0;
532
- var path = '';
533
- var defaultDelimiter = options && options.delimiter || '/';
534
- var res;
535
-
536
- while ((res = PATH_REGEXP.exec(str)) != null) {
537
- var m = res[0];
538
- var escaped = res[1];
539
- var offset = res.index;
540
- path += str.slice(index, offset);
541
- index = offset + m.length;
542
-
543
- // Ignore already escaped sequences.
544
- if (escaped) {
545
- path += escaped[1];
546
- continue
547
- }
548
-
549
- var next = str[index];
550
- var prefix = res[2];
551
- var name = res[3];
552
- var capture = res[4];
553
- var group = res[5];
554
- var modifier = res[6];
555
- var asterisk = res[7];
556
-
557
- // Push the current path onto the tokens.
558
- if (path) {
559
- tokens.push(path);
560
- path = '';
561
- }
562
-
563
- var partial = prefix != null && next != null && next !== prefix;
564
- var repeat = modifier === '+' || modifier === '*';
565
- var optional = modifier === '?' || modifier === '*';
566
- var delimiter = res[2] || defaultDelimiter;
567
- var pattern = capture || group;
568
-
569
- tokens.push({
570
- name: name || key++,
571
- prefix: prefix || '',
572
- delimiter: delimiter,
573
- optional: optional,
574
- repeat: repeat,
575
- partial: partial,
576
- asterisk: !!asterisk,
577
- pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
578
- });
579
- }
580
-
581
- // Match any characters still remaining.
582
- if (index < str.length) {
583
- path += str.substr(index);
584
- }
585
-
586
- // If the path exists, push it onto the end.
587
- if (path) {
588
- tokens.push(path);
589
- }
590
-
591
- return tokens
592
- }
593
-
594
- /**
595
- * Compile a string to a template function for the path.
596
- *
597
- * @param {string} str
598
- * @param {Object=} options
599
- * @return {!function(Object=, Object=)}
600
- */
601
- function compile (str, options) {
602
- return tokensToFunction(parse(str, options), options)
603
- }
604
-
605
- /**
606
- * Prettier encoding of URI path segments.
607
- *
608
- * @param {string}
609
- * @return {string}
610
- */
611
- function encodeURIComponentPretty (str) {
612
- return encodeURI(str).replace(/[\/?#]/g, function (c) {
613
- return '%' + c.charCodeAt(0).toString(16).toUpperCase()
614
- })
615
- }
616
-
617
- /**
618
- * Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
619
- *
620
- * @param {string}
621
- * @return {string}
622
- */
623
- function encodeAsterisk (str) {
624
- return encodeURI(str).replace(/[?#]/g, function (c) {
625
- return '%' + c.charCodeAt(0).toString(16).toUpperCase()
626
- })
627
- }
628
-
629
- /**
630
- * Expose a method for transforming tokens into the path function.
631
- */
632
- function tokensToFunction (tokens, options) {
633
- // Compile all the tokens into regexps.
634
- var matches = new Array(tokens.length);
635
-
636
- // Compile all the patterns before compilation.
637
- for (var i = 0; i < tokens.length; i++) {
638
- if (typeof tokens[i] === 'object') {
639
- matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options));
640
- }
641
- }
642
-
643
- return function (obj, opts) {
644
- var path = '';
645
- var data = obj || {};
646
- var options = opts || {};
647
- var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
648
-
649
- for (var i = 0; i < tokens.length; i++) {
650
- var token = tokens[i];
651
-
652
- if (typeof token === 'string') {
653
- path += token;
654
-
655
- continue
656
- }
657
-
658
- var value = data[token.name];
659
- var segment;
660
-
661
- if (value == null) {
662
- if (token.optional) {
663
- // Prepend partial segment prefixes.
664
- if (token.partial) {
665
- path += token.prefix;
666
- }
667
-
668
- continue
669
- } else {
670
- throw new TypeError('Expected "' + token.name + '" to be defined')
671
- }
672
- }
673
-
674
- if (isarray(value)) {
675
- if (!token.repeat) {
676
- throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
677
- }
678
-
679
- if (value.length === 0) {
680
- if (token.optional) {
681
- continue
682
- } else {
683
- throw new TypeError('Expected "' + token.name + '" to not be empty')
684
- }
685
- }
686
-
687
- for (var j = 0; j < value.length; j++) {
688
- segment = encode(value[j]);
689
-
690
- if (!matches[i].test(segment)) {
691
- throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
692
- }
693
-
694
- path += (j === 0 ? token.prefix : token.delimiter) + segment;
695
- }
696
-
697
- continue
698
- }
699
-
700
- segment = token.asterisk ? encodeAsterisk(value) : encode(value);
701
-
702
- if (!matches[i].test(segment)) {
703
- throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
704
- }
705
-
706
- path += token.prefix + segment;
707
- }
708
-
709
- return path
710
- }
711
- }
712
-
713
- /**
714
- * Escape a regular expression string.
715
- *
716
- * @param {string} str
717
- * @return {string}
718
- */
719
- function escapeString (str) {
720
- return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
721
- }
722
-
723
- /**
724
- * Escape the capturing group by escaping special characters and meaning.
725
- *
726
- * @param {string} group
727
- * @return {string}
728
- */
729
- function escapeGroup (group) {
730
- return group.replace(/([=!:$\/()])/g, '\\$1')
731
- }
732
-
733
- /**
734
- * Attach the keys as a property of the regexp.
735
- *
736
- * @param {!RegExp} re
737
- * @param {Array} keys
738
- * @return {!RegExp}
739
- */
740
- function attachKeys (re, keys) {
741
- re.keys = keys;
742
- return re
743
- }
744
-
745
- /**
746
- * Get the flags for a regexp from the options.
747
- *
748
- * @param {Object} options
749
- * @return {string}
750
- */
751
- function flags (options) {
752
- return options && options.sensitive ? '' : 'i'
753
- }
754
-
755
- /**
756
- * Pull out keys from a regexp.
757
- *
758
- * @param {!RegExp} path
759
- * @param {!Array} keys
760
- * @return {!RegExp}
761
- */
762
- function regexpToRegexp (path, keys) {
763
- // Use a negative lookahead to match only capturing groups.
764
- var groups = path.source.match(/\((?!\?)/g);
765
-
766
- if (groups) {
767
- for (var i = 0; i < groups.length; i++) {
768
- keys.push({
769
- name: i,
770
- prefix: null,
771
- delimiter: null,
772
- optional: false,
773
- repeat: false,
774
- partial: false,
775
- asterisk: false,
776
- pattern: null
777
- });
778
- }
779
- }
780
-
781
- return attachKeys(path, keys)
782
- }
783
-
784
- /**
785
- * Transform an array into a regexp.
786
- *
787
- * @param {!Array} path
788
- * @param {Array} keys
789
- * @param {!Object} options
790
- * @return {!RegExp}
791
- */
792
- function arrayToRegexp (path, keys, options) {
793
- var parts = [];
794
-
795
- for (var i = 0; i < path.length; i++) {
796
- parts.push(pathToRegexp(path[i], keys, options).source);
797
- }
798
-
799
- var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
800
-
801
- return attachKeys(regexp, keys)
802
- }
803
-
804
- /**
805
- * Create a path regexp from string input.
806
- *
807
- * @param {string} path
808
- * @param {!Array} keys
809
- * @param {!Object} options
810
- * @return {!RegExp}
811
- */
812
- function stringToRegexp (path, keys, options) {
813
- return tokensToRegExp(parse(path, options), keys, options)
814
- }
815
-
816
- /**
817
- * Expose a function for taking tokens and returning a RegExp.
818
- *
819
- * @param {!Array} tokens
820
- * @param {(Array|Object)=} keys
821
- * @param {Object=} options
822
- * @return {!RegExp}
823
- */
824
- function tokensToRegExp (tokens, keys, options) {
825
- if (!isarray(keys)) {
826
- options = /** @type {!Object} */ (keys || options);
827
- keys = [];
828
- }
829
-
830
- options = options || {};
831
-
832
- var strict = options.strict;
833
- var end = options.end !== false;
834
- var route = '';
835
-
836
- // Iterate over the tokens and create our regexp string.
837
- for (var i = 0; i < tokens.length; i++) {
838
- var token = tokens[i];
839
-
840
- if (typeof token === 'string') {
841
- route += escapeString(token);
842
- } else {
843
- var prefix = escapeString(token.prefix);
844
- var capture = '(?:' + token.pattern + ')';
845
-
846
- keys.push(token);
847
-
848
- if (token.repeat) {
849
- capture += '(?:' + prefix + capture + ')*';
850
- }
851
-
852
- if (token.optional) {
853
- if (!token.partial) {
854
- capture = '(?:' + prefix + '(' + capture + '))?';
855
- } else {
856
- capture = prefix + '(' + capture + ')?';
857
- }
858
- } else {
859
- capture = prefix + '(' + capture + ')';
860
- }
861
-
862
- route += capture;
863
- }
864
- }
865
-
866
- var delimiter = escapeString(options.delimiter || '/');
867
- var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
868
-
869
- // In non-strict mode we allow a slash at the end of match. If the path to
870
- // match already ends with a slash, we remove it for consistency. The slash
871
- // is valid at the end of a path match, not in the middle. This is important
872
- // in non-ending mode, where "/test/" shouldn't match "/test//route".
873
- if (!strict) {
874
- route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
875
- }
876
-
877
- if (end) {
878
- route += '$';
879
- } else {
880
- // In non-ending mode, we need the capturing groups to match as much as
881
- // possible by using a positive lookahead to the end or next path segment.
882
- route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
883
- }
884
-
885
- return attachKeys(new RegExp('^' + route, flags(options)), keys)
886
- }
887
-
888
- /**
889
- * Normalize the given path string, returning a regular expression.
890
- *
891
- * An empty array can be passed in for the keys, which will hold the
892
- * placeholder key descriptions. For example, using `/user/:id`, `keys` will
893
- * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
894
- *
895
- * @param {(string|RegExp|Array)} path
896
- * @param {(Array|Object)=} keys
897
- * @param {Object=} options
898
- * @return {!RegExp}
899
- */
900
- function pathToRegexp (path, keys, options) {
901
- if (!isarray(keys)) {
902
- options = /** @type {!Object} */ (keys || options);
903
- keys = [];
904
- }
905
-
906
- options = options || {};
907
-
908
- if (path instanceof RegExp) {
909
- return regexpToRegexp(path, /** @type {!Array} */ (keys))
910
- }
911
-
912
- if (isarray(path)) {
913
- return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
914
- }
915
-
916
- return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
917
- }
918
- pathToRegexp_1.parse = parse_1;
919
- pathToRegexp_1.compile = compile_1;
920
- pathToRegexp_1.tokensToFunction = tokensToFunction_1;
921
- pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
922
-
923
- /* */
924
-
925
- // $flow-disable-line
926
- var regexpCompileCache = Object.create(null);
927
-
928
- function fillParams (
929
- path,
930
- params,
931
- routeMsg
932
- ) {
933
- params = params || {};
934
- try {
935
- var filler =
936
- regexpCompileCache[path] ||
937
- (regexpCompileCache[path] = pathToRegexp_1.compile(path));
938
-
939
- // Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }}
940
- // and fix #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string
941
- if (typeof params.pathMatch === 'string') { params[0] = params.pathMatch; }
942
-
943
- return filler(params, { pretty: true })
944
- } catch (e) {
945
- {
946
- // Fix #3072 no warn if `pathMatch` is string
947
- warn(typeof params.pathMatch === 'string', ("missing param for " + routeMsg + ": " + (e.message)));
948
- }
949
- return ''
950
- } finally {
951
- // delete the 0 if it was added
952
- delete params[0];
953
- }
954
- }
955
-
956
- /* */
957
-
958
- function normalizeLocation (
959
- raw,
960
- current,
961
- append,
962
- router
963
- ) {
964
- var next = typeof raw === 'string' ? { path: raw } : raw;
965
- // named target
966
- if (next._normalized) {
967
- return next
968
- } else if (next.name) {
969
- next = extend({}, raw);
970
- var params = next.params;
971
- if (params && typeof params === 'object') {
972
- next.params = extend({}, params);
973
- }
974
- return next
975
- }
976
-
977
- // relative params
978
- if (!next.path && next.params && current) {
979
- next = extend({}, next);
980
- next._normalized = true;
981
- var params$1 = extend(extend({}, current.params), next.params);
982
- if (current.name) {
983
- next.name = current.name;
984
- next.params = params$1;
985
- } else if (current.matched.length) {
986
- var rawPath = current.matched[current.matched.length - 1].path;
987
- next.path = fillParams(rawPath, params$1, ("path " + (current.path)));
988
- } else {
989
- warn(false, "relative params navigation requires a current route.");
990
- }
991
- return next
992
- }
993
-
994
- var parsedPath = parsePath(next.path || '');
995
- var basePath = (current && current.path) || '/';
996
- var path = parsedPath.path
997
- ? resolvePath(parsedPath.path, basePath, append || next.append)
998
- : basePath;
999
-
1000
- var query = resolveQuery(
1001
- parsedPath.query,
1002
- next.query,
1003
- router && router.options.parseQuery
1004
- );
1005
-
1006
- var hash = next.hash || parsedPath.hash;
1007
- if (hash && hash.charAt(0) !== '#') {
1008
- hash = "#" + hash;
1009
- }
1010
-
1011
- return {
1012
- _normalized: true,
1013
- path: path,
1014
- query: query,
1015
- hash: hash
1016
- }
1017
- }
1018
-
1019
- /* */
1020
-
1021
- // work around weird flow bug
1022
- var toTypes = [String, Object];
1023
- var eventTypes = [String, Array];
1024
-
1025
- var noop = function () {};
1026
-
1027
- var Link = {
1028
- name: 'RouterLink',
1029
- props: {
1030
- to: {
1031
- type: toTypes,
1032
- required: true
1033
- },
1034
- tag: {
1035
- type: String,
1036
- default: 'a'
1037
- },
1038
- exact: Boolean,
1039
- append: Boolean,
1040
- replace: Boolean,
1041
- activeClass: String,
1042
- exactActiveClass: String,
1043
- ariaCurrentValue: {
1044
- type: String,
1045
- default: 'page'
1046
- },
1047
- event: {
1048
- type: eventTypes,
1049
- default: 'click'
1050
- }
1051
- },
1052
- render: function render (h) {
1053
- var this$1 = this;
1054
-
1055
- var router = this.$router;
1056
- var current = this.$route;
1057
- var ref = router.resolve(
1058
- this.to,
1059
- current,
1060
- this.append
1061
- );
1062
- var location = ref.location;
1063
- var route = ref.route;
1064
- var href = ref.href;
1065
-
1066
- var classes = {};
1067
- var globalActiveClass = router.options.linkActiveClass;
1068
- var globalExactActiveClass = router.options.linkExactActiveClass;
1069
- // Support global empty active class
1070
- var activeClassFallback =
1071
- globalActiveClass == null ? 'router-link-active' : globalActiveClass;
1072
- var exactActiveClassFallback =
1073
- globalExactActiveClass == null
1074
- ? 'router-link-exact-active'
1075
- : globalExactActiveClass;
1076
- var activeClass =
1077
- this.activeClass == null ? activeClassFallback : this.activeClass;
1078
- var exactActiveClass =
1079
- this.exactActiveClass == null
1080
- ? exactActiveClassFallback
1081
- : this.exactActiveClass;
1082
-
1083
- var compareTarget = route.redirectedFrom
1084
- ? createRoute(null, normalizeLocation(route.redirectedFrom), null, router)
1085
- : route;
1086
-
1087
- classes[exactActiveClass] = isSameRoute(current, compareTarget);
1088
- classes[activeClass] = this.exact
1089
- ? classes[exactActiveClass]
1090
- : isIncludedRoute(current, compareTarget);
1091
-
1092
- var ariaCurrentValue = classes[exactActiveClass] ? this.ariaCurrentValue : null;
1093
-
1094
- var handler = function (e) {
1095
- if (guardEvent(e)) {
1096
- if (this$1.replace) {
1097
- router.replace(location, noop);
1098
- } else {
1099
- router.push(location, noop);
1100
- }
1101
- }
1102
- };
1103
-
1104
- var on = { click: guardEvent };
1105
- if (Array.isArray(this.event)) {
1106
- this.event.forEach(function (e) {
1107
- on[e] = handler;
1108
- });
1109
- } else {
1110
- on[this.event] = handler;
1111
- }
1112
-
1113
- var data = { class: classes };
1114
-
1115
- var scopedSlot =
1116
- !this.$scopedSlots.$hasNormal &&
1117
- this.$scopedSlots.default &&
1118
- this.$scopedSlots.default({
1119
- href: href,
1120
- route: route,
1121
- navigate: handler,
1122
- isActive: classes[activeClass],
1123
- isExactActive: classes[exactActiveClass]
1124
- });
1125
-
1126
- if (scopedSlot) {
1127
- if (scopedSlot.length === 1) {
1128
- return scopedSlot[0]
1129
- } else if (scopedSlot.length > 1 || !scopedSlot.length) {
1130
- {
1131
- warn(
1132
- false,
1133
- ("RouterLink with to=\"" + (this.to) + "\" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element.")
1134
- );
1135
- }
1136
- return scopedSlot.length === 0 ? h() : h('span', {}, scopedSlot)
1137
- }
1138
- }
1139
-
1140
- if (this.tag === 'a') {
1141
- data.on = on;
1142
- data.attrs = { href: href, 'aria-current': ariaCurrentValue };
1143
- } else {
1144
- // find the first <a> child and apply listener and href
1145
- var a = findAnchor(this.$slots.default);
1146
- if (a) {
1147
- // in case the <a> is a static node
1148
- a.isStatic = false;
1149
- var aData = (a.data = extend({}, a.data));
1150
- aData.on = aData.on || {};
1151
- // transform existing events in both objects into arrays so we can push later
1152
- for (var event in aData.on) {
1153
- var handler$1 = aData.on[event];
1154
- if (event in on) {
1155
- aData.on[event] = Array.isArray(handler$1) ? handler$1 : [handler$1];
1156
- }
1157
- }
1158
- // append new listeners for router-link
1159
- for (var event$1 in on) {
1160
- if (event$1 in aData.on) {
1161
- // on[event] is always a function
1162
- aData.on[event$1].push(on[event$1]);
1163
- } else {
1164
- aData.on[event$1] = handler;
1165
- }
1166
- }
1167
-
1168
- var aAttrs = (a.data.attrs = extend({}, a.data.attrs));
1169
- aAttrs.href = href;
1170
- aAttrs['aria-current'] = ariaCurrentValue;
1171
- } else {
1172
- // doesn't have <a> child, apply listener to self
1173
- data.on = on;
1174
- }
1175
- }
1176
-
1177
- return h(this.tag, data, this.$slots.default)
1178
- }
1179
- };
1180
-
1181
- function guardEvent (e) {
1182
- // don't redirect with control keys
1183
- if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) { return }
1184
- // don't redirect when preventDefault called
1185
- if (e.defaultPrevented) { return }
1186
- // don't redirect on right click
1187
- if (e.button !== undefined && e.button !== 0) { return }
1188
- // don't redirect if `target="_blank"`
1189
- if (e.currentTarget && e.currentTarget.getAttribute) {
1190
- var target = e.currentTarget.getAttribute('target');
1191
- if (/\b_blank\b/i.test(target)) { return }
1192
- }
1193
- // this may be a Weex event which doesn't have this method
1194
- if (e.preventDefault) {
1195
- e.preventDefault();
1196
- }
1197
- return true
1198
- }
1199
-
1200
- function findAnchor (children) {
1201
- if (children) {
1202
- var child;
1203
- for (var i = 0; i < children.length; i++) {
1204
- child = children[i];
1205
- if (child.tag === 'a') {
1206
- return child
1207
- }
1208
- if (child.children && (child = findAnchor(child.children))) {
1209
- return child
1210
- }
1211
- }
1212
- }
1213
- }
1214
-
1215
- var _Kdu;
1216
-
1217
- function install (Kdu) {
1218
- if (install.installed && _Kdu === Kdu) { return }
1219
- install.installed = true;
1220
-
1221
- _Kdu = Kdu;
1222
-
1223
- var isDef = function (v) { return v !== undefined; };
1224
-
1225
- var registerInstance = function (vm, callVal) {
1226
- var i = vm.$options._parentKnode;
1227
- if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) {
1228
- i(vm, callVal);
1229
- }
1230
- };
1231
-
1232
- Kdu.mixin({
1233
- beforeCreate: function beforeCreate () {
1234
- if (isDef(this.$options.router)) {
1235
- this._routerRoot = this;
1236
- this._router = this.$options.router;
1237
- this._router.init(this);
1238
- Kdu.util.defineReactive(this, '_route', this._router.history.current);
1239
- } else {
1240
- this._routerRoot = (this.$parent && this.$parent._routerRoot) || this;
1241
- }
1242
- registerInstance(this, this);
1243
- },
1244
- destroyed: function destroyed () {
1245
- registerInstance(this);
1246
- }
1247
- });
1248
-
1249
- Object.defineProperty(Kdu.prototype, '$router', {
1250
- get: function get () { return this._routerRoot._router }
1251
- });
1252
-
1253
- Object.defineProperty(Kdu.prototype, '$route', {
1254
- get: function get () { return this._routerRoot._route }
1255
- });
1256
-
1257
- Kdu.component('RouterView', View);
1258
- Kdu.component('RouterLink', Link);
1259
-
1260
- var strats = Kdu.config.optionMergeStrategies;
1261
- // use the same hook merging strategy for route hooks
1262
- strats.beforeRouteEnter = strats.beforeRouteLeave = strats.beforeRouteUpdate = strats.created;
1263
- }
1264
-
1265
- /* */
1266
-
1267
- var inBrowser = typeof window !== 'undefined';
1268
-
1269
- /* */
1270
-
1271
- function createRouteMap (
1272
- routes,
1273
- oldPathList,
1274
- oldPathMap,
1275
- oldNameMap
1276
- ) {
1277
- // the path list is used to control path matching priority
1278
- var pathList = oldPathList || [];
1279
- // $flow-disable-line
1280
- var pathMap = oldPathMap || Object.create(null);
1281
- // $flow-disable-line
1282
- var nameMap = oldNameMap || Object.create(null);
1283
-
1284
- routes.forEach(function (route) {
1285
- addRouteRecord(pathList, pathMap, nameMap, route);
1286
- });
1287
-
1288
- // ensure wildcard routes are always at the end
1289
- for (var i = 0, l = pathList.length; i < l; i++) {
1290
- if (pathList[i] === '*') {
1291
- pathList.push(pathList.splice(i, 1)[0]);
1292
- l--;
1293
- i--;
1294
- }
1295
- }
1296
-
1297
- {
1298
- // warn if routes do not include leading slashes
1299
- var found = pathList
1300
- // check for missing leading slash
1301
- .filter(function (path) { return path && path.charAt(0) !== '*' && path.charAt(0) !== '/'; });
1302
-
1303
- if (found.length > 0) {
1304
- var pathNames = found.map(function (path) { return ("- " + path); }).join('\n');
1305
- warn(false, ("Non-nested routes must include a leading slash character. Fix the following routes: \n" + pathNames));
1306
- }
1307
- }
1308
-
1309
- return {
1310
- pathList: pathList,
1311
- pathMap: pathMap,
1312
- nameMap: nameMap
1313
- }
1314
- }
1315
-
1316
- function addRouteRecord (
1317
- pathList,
1318
- pathMap,
1319
- nameMap,
1320
- route,
1321
- parent,
1322
- matchAs
1323
- ) {
1324
- var path = route.path;
1325
- var name = route.name;
1326
- {
1327
- assert(path != null, "\"path\" is required in a route configuration.");
1328
- assert(
1329
- typeof route.component !== 'string',
1330
- "route config \"component\" for path: " + (String(
1331
- path || name
1332
- )) + " cannot be a " + "string id. Use an actual component instead."
1333
- );
1334
- }
1335
-
1336
- var pathToRegexpOptions =
1337
- route.pathToRegexpOptions || {};
1338
- var normalizedPath = normalizePath(path, parent, pathToRegexpOptions.strict);
1339
-
1340
- if (typeof route.caseSensitive === 'boolean') {
1341
- pathToRegexpOptions.sensitive = route.caseSensitive;
1342
- }
1343
-
1344
- var record = {
1345
- path: normalizedPath,
1346
- regex: compileRouteRegex(normalizedPath, pathToRegexpOptions),
1347
- components: route.components || { default: route.component },
1348
- instances: {},
1349
- name: name,
1350
- parent: parent,
1351
- matchAs: matchAs,
1352
- redirect: route.redirect,
1353
- beforeEnter: route.beforeEnter,
1354
- meta: route.meta || {},
1355
- props:
1356
- route.props == null
1357
- ? {}
1358
- : route.components
1359
- ? route.props
1360
- : { default: route.props }
1361
- };
1362
-
1363
- if (route.children) {
1364
- // Warn if route is named, does not redirect and has a default child route.
1365
- // If users navigate to this route by name, the default child will
1366
- // not be rendered (GH Issue #629)
1367
- {
1368
- if (
1369
- route.name &&
1370
- !route.redirect &&
1371
- route.children.some(function (child) { return /^\/?$/.test(child.path); })
1372
- ) {
1373
- warn(
1374
- false,
1375
- "Named Route '" + (route.name) + "' has a default child route. " +
1376
- "When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), " +
1377
- "the default child route will not be rendered. Remove the name from " +
1378
- "this route and use the name of the default child route for named " +
1379
- "links instead."
1380
- );
1381
- }
1382
- }
1383
- route.children.forEach(function (child) {
1384
- var childMatchAs = matchAs
1385
- ? cleanPath((matchAs + "/" + (child.path)))
1386
- : undefined;
1387
- addRouteRecord(pathList, pathMap, nameMap, child, record, childMatchAs);
1388
- });
1389
- }
1390
-
1391
- if (!pathMap[record.path]) {
1392
- pathList.push(record.path);
1393
- pathMap[record.path] = record;
1394
- }
1395
-
1396
- if (route.alias !== undefined) {
1397
- var aliases = Array.isArray(route.alias) ? route.alias : [route.alias];
1398
- for (var i = 0; i < aliases.length; ++i) {
1399
- var alias = aliases[i];
1400
- if ( alias === path) {
1401
- warn(
1402
- false,
1403
- ("Found an alias with the same value as the path: \"" + path + "\". You have to remove that alias. It will be ignored in development.")
1404
- );
1405
- // skip in dev to make it work
1406
- continue
1407
- }
1408
-
1409
- var aliasRoute = {
1410
- path: alias,
1411
- children: route.children
1412
- };
1413
- addRouteRecord(
1414
- pathList,
1415
- pathMap,
1416
- nameMap,
1417
- aliasRoute,
1418
- parent,
1419
- record.path || '/' // matchAs
1420
- );
1421
- }
1422
- }
1423
-
1424
- if (name) {
1425
- if (!nameMap[name]) {
1426
- nameMap[name] = record;
1427
- } else if ( !matchAs) {
1428
- warn(
1429
- false,
1430
- "Duplicate named routes definition: " +
1431
- "{ name: \"" + name + "\", path: \"" + (record.path) + "\" }"
1432
- );
1433
- }
1434
- }
1435
- }
1436
-
1437
- function compileRouteRegex (
1438
- path,
1439
- pathToRegexpOptions
1440
- ) {
1441
- var regex = pathToRegexp_1(path, [], pathToRegexpOptions);
1442
- {
1443
- var keys = Object.create(null);
1444
- regex.keys.forEach(function (key) {
1445
- warn(
1446
- !keys[key.name],
1447
- ("Duplicate param keys in route with path: \"" + path + "\"")
1448
- );
1449
- keys[key.name] = true;
1450
- });
1451
- }
1452
- return regex
1453
- }
1454
-
1455
- function normalizePath (
1456
- path,
1457
- parent,
1458
- strict
1459
- ) {
1460
- if (!strict) { path = path.replace(/\/$/, ''); }
1461
- if (path[0] === '/') { return path }
1462
- if (parent == null) { return path }
1463
- return cleanPath(((parent.path) + "/" + path))
1464
- }
1465
-
1466
- /* */
1467
-
1468
-
1469
-
1470
- function createMatcher (
1471
- routes,
1472
- router
1473
- ) {
1474
- var ref = createRouteMap(routes);
1475
- var pathList = ref.pathList;
1476
- var pathMap = ref.pathMap;
1477
- var nameMap = ref.nameMap;
1478
-
1479
- function addRoutes (routes) {
1480
- createRouteMap(routes, pathList, pathMap, nameMap);
1481
- }
1482
-
1483
- function match (
1484
- raw,
1485
- currentRoute,
1486
- redirectedFrom
1487
- ) {
1488
- var location = normalizeLocation(raw, currentRoute, false, router);
1489
- var name = location.name;
1490
-
1491
- if (name) {
1492
- var record = nameMap[name];
1493
- {
1494
- warn(record, ("Route with name '" + name + "' does not exist"));
1495
- }
1496
- if (!record) { return _createRoute(null, location) }
1497
- var paramNames = record.regex.keys
1498
- .filter(function (key) { return !key.optional; })
1499
- .map(function (key) { return key.name; });
1500
-
1501
- if (typeof location.params !== 'object') {
1502
- location.params = {};
1503
- }
1504
-
1505
- if (currentRoute && typeof currentRoute.params === 'object') {
1506
- for (var key in currentRoute.params) {
1507
- if (!(key in location.params) && paramNames.indexOf(key) > -1) {
1508
- location.params[key] = currentRoute.params[key];
1509
- }
1510
- }
1511
- }
1512
-
1513
- location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1514
- return _createRoute(record, location, redirectedFrom)
1515
- } else if (location.path) {
1516
- location.params = {};
1517
- for (var i = 0; i < pathList.length; i++) {
1518
- var path = pathList[i];
1519
- var record$1 = pathMap[path];
1520
- if (matchRoute(record$1.regex, location.path, location.params)) {
1521
- return _createRoute(record$1, location, redirectedFrom)
1522
- }
1523
- }
1524
- }
1525
- // no match
1526
- return _createRoute(null, location)
1527
- }
1528
-
1529
- function redirect (
1530
- record,
1531
- location
1532
- ) {
1533
- var originalRedirect = record.redirect;
1534
- var redirect = typeof originalRedirect === 'function'
1535
- ? originalRedirect(createRoute(record, location, null, router))
1536
- : originalRedirect;
1537
-
1538
- if (typeof redirect === 'string') {
1539
- redirect = { path: redirect };
1540
- }
1541
-
1542
- if (!redirect || typeof redirect !== 'object') {
1543
- {
1544
- warn(
1545
- false, ("invalid redirect option: " + (JSON.stringify(redirect)))
1546
- );
1547
- }
1548
- return _createRoute(null, location)
1549
- }
1550
-
1551
- var re = redirect;
1552
- var name = re.name;
1553
- var path = re.path;
1554
- var query = location.query;
1555
- var hash = location.hash;
1556
- var params = location.params;
1557
- query = re.hasOwnProperty('query') ? re.query : query;
1558
- hash = re.hasOwnProperty('hash') ? re.hash : hash;
1559
- params = re.hasOwnProperty('params') ? re.params : params;
1560
-
1561
- if (name) {
1562
- // resolved named direct
1563
- var targetRecord = nameMap[name];
1564
- {
1565
- assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found."));
1566
- }
1567
- return match({
1568
- _normalized: true,
1569
- name: name,
1570
- query: query,
1571
- hash: hash,
1572
- params: params
1573
- }, undefined, location)
1574
- } else if (path) {
1575
- // 1. resolve relative redirect
1576
- var rawPath = resolveRecordPath(path, record);
1577
- // 2. resolve params
1578
- var resolvedPath = fillParams(rawPath, params, ("redirect route with path \"" + rawPath + "\""));
1579
- // 3. rematch with existing query and hash
1580
- return match({
1581
- _normalized: true,
1582
- path: resolvedPath,
1583
- query: query,
1584
- hash: hash
1585
- }, undefined, location)
1586
- } else {
1587
- {
1588
- warn(false, ("invalid redirect option: " + (JSON.stringify(redirect))));
1589
- }
1590
- return _createRoute(null, location)
1591
- }
1592
- }
1593
-
1594
- function alias (
1595
- record,
1596
- location,
1597
- matchAs
1598
- ) {
1599
- var aliasedPath = fillParams(matchAs, location.params, ("aliased route with path \"" + matchAs + "\""));
1600
- var aliasedMatch = match({
1601
- _normalized: true,
1602
- path: aliasedPath
1603
- });
1604
- if (aliasedMatch) {
1605
- var matched = aliasedMatch.matched;
1606
- var aliasedRecord = matched[matched.length - 1];
1607
- location.params = aliasedMatch.params;
1608
- return _createRoute(aliasedRecord, location)
1609
- }
1610
- return _createRoute(null, location)
1611
- }
1612
-
1613
- function _createRoute (
1614
- record,
1615
- location,
1616
- redirectedFrom
1617
- ) {
1618
- if (record && record.redirect) {
1619
- return redirect(record, redirectedFrom || location)
1620
- }
1621
- if (record && record.matchAs) {
1622
- return alias(record, location, record.matchAs)
1623
- }
1624
- return createRoute(record, location, redirectedFrom, router)
1625
- }
1626
-
1627
- return {
1628
- match: match,
1629
- addRoutes: addRoutes
1630
- }
1631
- }
1632
-
1633
- function matchRoute (
1634
- regex,
1635
- path,
1636
- params
1637
- ) {
1638
- var m = path.match(regex);
1639
-
1640
- if (!m) {
1641
- return false
1642
- } else if (!params) {
1643
- return true
1644
- }
1645
-
1646
- for (var i = 1, len = m.length; i < len; ++i) {
1647
- var key = regex.keys[i - 1];
1648
- var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i];
1649
- if (key) {
1650
- // Fix #1994: using * with props: true generates a param named 0
1651
- params[key.name || 'pathMatch'] = val;
1652
- }
1653
- }
1654
-
1655
- return true
1656
- }
1657
-
1658
- function resolveRecordPath (path, record) {
1659
- return resolvePath(path, record.parent ? record.parent.path : '/', true)
1660
- }
1661
-
1662
- /* */
1663
-
1664
- // use User Timing api (if present) for more accurate key precision
1665
- var Time =
1666
- inBrowser && window.performance && window.performance.now
1667
- ? window.performance
1668
- : Date;
1669
-
1670
- function genStateKey () {
1671
- return Time.now().toFixed(3)
1672
- }
1673
-
1674
- var _key = genStateKey();
1675
-
1676
- function getStateKey () {
1677
- return _key
1678
- }
1679
-
1680
- function setStateKey (key) {
1681
- return (_key = key)
1682
- }
1683
-
1684
- /* */
1685
-
1686
- var positionStore = Object.create(null);
1687
-
1688
- function setupScroll () {
1689
- // Prevent browser scroll behavior on History popstate
1690
- if ('scrollRestoration' in window.history) {
1691
- window.history.scrollRestoration = 'manual';
1692
- }
1693
- // Fix for #1585 for Firefox
1694
- // Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1695
- // Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
1696
- // window.location.protocol + '//' + window.location.host
1697
- // location.host contains the port and location.hostname doesn't
1698
- var protocolAndPath = window.location.protocol + '//' + window.location.host;
1699
- var absolutePath = window.location.href.replace(protocolAndPath, '');
1700
- // preserve existing history state as it could be overriden by the user
1701
- var stateCopy = extend({}, window.history.state);
1702
- stateCopy.key = getStateKey();
1703
- window.history.replaceState(stateCopy, '', absolutePath);
1704
- window.addEventListener('popstate', handlePopState);
1705
- return function () {
1706
- window.removeEventListener('popstate', handlePopState);
1707
- }
1708
- }
1709
-
1710
- function handleScroll (
1711
- router,
1712
- to,
1713
- from,
1714
- isPop
1715
- ) {
1716
- if (!router.app) {
1717
- return
1718
- }
1719
-
1720
- var behavior = router.options.scrollBehavior;
1721
- if (!behavior) {
1722
- return
1723
- }
1724
-
1725
- {
1726
- assert(typeof behavior === 'function', "scrollBehavior must be a function");
1727
- }
1728
-
1729
- // wait until re-render finishes before scrolling
1730
- router.app.$nextTick(function () {
1731
- var position = getScrollPosition();
1732
- var shouldScroll = behavior.call(
1733
- router,
1734
- to,
1735
- from,
1736
- isPop ? position : null
1737
- );
1738
-
1739
- if (!shouldScroll) {
1740
- return
1741
- }
1742
-
1743
- if (typeof shouldScroll.then === 'function') {
1744
- shouldScroll
1745
- .then(function (shouldScroll) {
1746
- scrollToPosition((shouldScroll), position);
1747
- })
1748
- .catch(function (err) {
1749
- {
1750
- assert(false, err.toString());
1751
- }
1752
- });
1753
- } else {
1754
- scrollToPosition(shouldScroll, position);
1755
- }
1756
- });
1757
- }
1758
-
1759
- function saveScrollPosition () {
1760
- var key = getStateKey();
1761
- if (key) {
1762
- positionStore[key] = {
1763
- x: window.pageXOffset,
1764
- y: window.pageYOffset
1765
- };
1766
- }
1767
- }
1768
-
1769
- function handlePopState (e) {
1770
- saveScrollPosition();
1771
- if (e.state && e.state.key) {
1772
- setStateKey(e.state.key);
1773
- }
1774
- }
1775
-
1776
- function getScrollPosition () {
1777
- var key = getStateKey();
1778
- if (key) {
1779
- return positionStore[key]
1780
- }
1781
- }
1782
-
1783
- function getElementPosition (el, offset) {
1784
- var docEl = document.documentElement;
1785
- var docRect = docEl.getBoundingClientRect();
1786
- var elRect = el.getBoundingClientRect();
1787
- return {
1788
- x: elRect.left - docRect.left - offset.x,
1789
- y: elRect.top - docRect.top - offset.y
1790
- }
1791
- }
1792
-
1793
- function isValidPosition (obj) {
1794
- return isNumber(obj.x) || isNumber(obj.y)
1795
- }
1796
-
1797
- function normalizePosition (obj) {
1798
- return {
1799
- x: isNumber(obj.x) ? obj.x : window.pageXOffset,
1800
- y: isNumber(obj.y) ? obj.y : window.pageYOffset
1801
- }
1802
- }
1803
-
1804
- function normalizeOffset (obj) {
1805
- return {
1806
- x: isNumber(obj.x) ? obj.x : 0,
1807
- y: isNumber(obj.y) ? obj.y : 0
1808
- }
1809
- }
1810
-
1811
- function isNumber (v) {
1812
- return typeof v === 'number'
1813
- }
1814
-
1815
- var hashStartsWithNumberRE = /^#\d/;
1816
-
1817
- function scrollToPosition (shouldScroll, position) {
1818
- var isObject = typeof shouldScroll === 'object';
1819
- if (isObject && typeof shouldScroll.selector === 'string') {
1820
- // getElementById would still fail if the selector contains a more complicated query like #main[data-attr]
1821
- // but at the same time, it doesn't make much sense to select an element with an id and an extra selector
1822
- var el = hashStartsWithNumberRE.test(shouldScroll.selector) // $flow-disable-line
1823
- ? document.getElementById(shouldScroll.selector.slice(1)) // $flow-disable-line
1824
- : document.querySelector(shouldScroll.selector);
1825
-
1826
- if (el) {
1827
- var offset =
1828
- shouldScroll.offset && typeof shouldScroll.offset === 'object'
1829
- ? shouldScroll.offset
1830
- : {};
1831
- offset = normalizeOffset(offset);
1832
- position = getElementPosition(el, offset);
1833
- } else if (isValidPosition(shouldScroll)) {
1834
- position = normalizePosition(shouldScroll);
1835
- }
1836
- } else if (isObject && isValidPosition(shouldScroll)) {
1837
- position = normalizePosition(shouldScroll);
1838
- }
1839
-
1840
- if (position) {
1841
- window.scrollTo(position.x, position.y);
1842
- }
1843
- }
1844
-
1845
- /* */
1846
-
1847
- var supportsPushState =
1848
- inBrowser &&
1849
- (function () {
1850
- var ua = window.navigator.userAgent;
1851
-
1852
- if (
1853
- (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
1854
- ua.indexOf('Mobile Safari') !== -1 &&
1855
- ua.indexOf('Chrome') === -1 &&
1856
- ua.indexOf('Windows Phone') === -1
1857
- ) {
1858
- return false
1859
- }
1860
-
1861
- return window.history && typeof window.history.pushState === 'function'
1862
- })();
1863
-
1864
- function pushState (url, replace) {
1865
- saveScrollPosition();
1866
- // try...catch the pushState call to get around Safari
1867
- // DOM Exception 18 where it limits to 100 pushState calls
1868
- var history = window.history;
1869
- try {
1870
- if (replace) {
1871
- // preserve existing history state as it could be overriden by the user
1872
- var stateCopy = extend({}, history.state);
1873
- stateCopy.key = getStateKey();
1874
- history.replaceState(stateCopy, '', url);
1875
- } else {
1876
- history.pushState({ key: setStateKey(genStateKey()) }, '', url);
1877
- }
1878
- } catch (e) {
1879
- window.location[replace ? 'replace' : 'assign'](url);
1880
- }
1881
- }
1882
-
1883
- function replaceState (url) {
1884
- pushState(url, true);
1885
- }
1886
-
1887
- /* */
1888
-
1889
- function runQueue (queue, fn, cb) {
1890
- var step = function (index) {
1891
- if (index >= queue.length) {
1892
- cb();
1893
- } else {
1894
- if (queue[index]) {
1895
- fn(queue[index], function () {
1896
- step(index + 1);
1897
- });
1898
- } else {
1899
- step(index + 1);
1900
- }
1901
- }
1902
- };
1903
- step(0);
1904
- }
1905
-
1906
- var NavigationFailureType = {
1907
- redirected: 2,
1908
- aborted: 4,
1909
- cancelled: 8,
1910
- duplicated: 16
1911
- };
1912
-
1913
- function createNavigationRedirectedError (from, to) {
1914
- return createRouterError(
1915
- from,
1916
- to,
1917
- NavigationFailureType.redirected,
1918
- ("Redirected when going from \"" + (from.fullPath) + "\" to \"" + (stringifyRoute(
1919
- to
1920
- )) + "\" via a navigation guard.")
1921
- )
1922
- }
1923
-
1924
- function createNavigationDuplicatedError (from, to) {
1925
- var error = createRouterError(
1926
- from,
1927
- to,
1928
- NavigationFailureType.duplicated,
1929
- ("Avoided redundant navigation to current location: \"" + (from.fullPath) + "\".")
1930
- );
1931
- // backwards compatible with the first introduction of Errors
1932
- error.name = 'NavigationDuplicated';
1933
- return error
1934
- }
1935
-
1936
- function createNavigationCancelledError (from, to) {
1937
- return createRouterError(
1938
- from,
1939
- to,
1940
- NavigationFailureType.cancelled,
1941
- ("Navigation cancelled from \"" + (from.fullPath) + "\" to \"" + (to.fullPath) + "\" with a new navigation.")
1942
- )
1943
- }
1944
-
1945
- function createNavigationAbortedError (from, to) {
1946
- return createRouterError(
1947
- from,
1948
- to,
1949
- NavigationFailureType.aborted,
1950
- ("Navigation aborted from \"" + (from.fullPath) + "\" to \"" + (to.fullPath) + "\" via a navigation guard.")
1951
- )
1952
- }
1953
-
1954
- function createRouterError (from, to, type, message) {
1955
- var error = new Error(message);
1956
- error._isRouter = true;
1957
- error.from = from;
1958
- error.to = to;
1959
- error.type = type;
1960
-
1961
- return error
1962
- }
1963
-
1964
- var propertiesToLog = ['params', 'query', 'hash'];
1965
-
1966
- function stringifyRoute (to) {
1967
- if (typeof to === 'string') { return to }
1968
- if ('path' in to) { return to.path }
1969
- var location = {};
1970
- propertiesToLog.forEach(function (key) {
1971
- if (key in to) { location[key] = to[key]; }
1972
- });
1973
- return JSON.stringify(location, null, 2)
1974
- }
1975
-
1976
- function isError (err) {
1977
- return Object.prototype.toString.call(err).indexOf('Error') > -1
1978
- }
1979
-
1980
- function isNavigationFailure (err, errorType) {
1981
- return (
1982
- isError(err) &&
1983
- err._isRouter &&
1984
- (errorType == null || err.type === errorType)
1985
- )
1986
- }
1987
-
1988
- /* */
1989
-
1990
- function resolveAsyncComponents (matched) {
1991
- return function (to, from, next) {
1992
- var hasAsync = false;
1993
- var pending = 0;
1994
- var error = null;
1995
-
1996
- flatMapComponents(matched, function (def, _, match, key) {
1997
- // if it's a function and doesn't have cid attached,
1998
- // assume it's an async component resolve function.
1999
- // we are not using Kdu's default async resolving mechanism because
2000
- // we want to halt the navigation until the incoming component has been
2001
- // resolved.
2002
- if (typeof def === 'function' && def.cid === undefined) {
2003
- hasAsync = true;
2004
- pending++;
2005
-
2006
- var resolve = once(function (resolvedDef) {
2007
- if (isESModule(resolvedDef)) {
2008
- resolvedDef = resolvedDef.default;
2009
- }
2010
- // save resolved on async factory in case it's used elsewhere
2011
- def.resolved = typeof resolvedDef === 'function'
2012
- ? resolvedDef
2013
- : _Kdu.extend(resolvedDef);
2014
- match.components[key] = resolvedDef;
2015
- pending--;
2016
- if (pending <= 0) {
2017
- next();
2018
- }
2019
- });
2020
-
2021
- var reject = once(function (reason) {
2022
- var msg = "Failed to resolve async component " + key + ": " + reason;
2023
- warn(false, msg);
2024
- if (!error) {
2025
- error = isError(reason)
2026
- ? reason
2027
- : new Error(msg);
2028
- next(error);
2029
- }
2030
- });
2031
-
2032
- var res;
2033
- try {
2034
- res = def(resolve, reject);
2035
- } catch (e) {
2036
- reject(e);
2037
- }
2038
- if (res) {
2039
- if (typeof res.then === 'function') {
2040
- res.then(resolve, reject);
2041
- } else {
2042
- // new syntax in Kdu 2.3
2043
- var comp = res.component;
2044
- if (comp && typeof comp.then === 'function') {
2045
- comp.then(resolve, reject);
2046
- }
2047
- }
2048
- }
2049
- }
2050
- });
2051
-
2052
- if (!hasAsync) { next(); }
2053
- }
2054
- }
2055
-
2056
- function flatMapComponents (
2057
- matched,
2058
- fn
2059
- ) {
2060
- return flatten(matched.map(function (m) {
2061
- return Object.keys(m.components).map(function (key) { return fn(
2062
- m.components[key],
2063
- m.instances[key],
2064
- m, key
2065
- ); })
2066
- }))
2067
- }
2068
-
2069
- function flatten (arr) {
2070
- return Array.prototype.concat.apply([], arr)
2071
- }
2072
-
2073
- var hasSymbol =
2074
- typeof Symbol === 'function' &&
2075
- typeof Symbol.toStringTag === 'symbol';
2076
-
2077
- function isESModule (obj) {
2078
- return obj.__esModule || (hasSymbol && obj[Symbol.toStringTag] === 'Module')
2079
- }
2080
-
2081
- // in Webpack 2, require.ensure now also returns a Promise
2082
- // so the resolve/reject functions may get called an extra time
2083
- // if the user uses an arrow function shorthand that happens to
2084
- // return that Promise.
2085
- function once (fn) {
2086
- var called = false;
2087
- return function () {
2088
- var args = [], len = arguments.length;
2089
- while ( len-- ) args[ len ] = arguments[ len ];
2090
-
2091
- if (called) { return }
2092
- called = true;
2093
- return fn.apply(this, args)
2094
- }
2095
- }
2096
-
2097
- /* */
2098
-
2099
- var History = function History (router, base) {
2100
- this.router = router;
2101
- this.base = normalizeBase(base);
2102
- // start with a route object that stands for "nowhere"
2103
- this.current = START;
2104
- this.pending = null;
2105
- this.ready = false;
2106
- this.readyCbs = [];
2107
- this.readyErrorCbs = [];
2108
- this.errorCbs = [];
2109
- this.listeners = [];
2110
- };
2111
-
2112
- History.prototype.listen = function listen (cb) {
2113
- this.cb = cb;
2114
- };
2115
-
2116
- History.prototype.onReady = function onReady (cb, errorCb) {
2117
- if (this.ready) {
2118
- cb();
2119
- } else {
2120
- this.readyCbs.push(cb);
2121
- if (errorCb) {
2122
- this.readyErrorCbs.push(errorCb);
2123
- }
2124
- }
2125
- };
2126
-
2127
- History.prototype.onError = function onError (errorCb) {
2128
- this.errorCbs.push(errorCb);
2129
- };
2130
-
2131
- History.prototype.transitionTo = function transitionTo (
2132
- location,
2133
- onComplete,
2134
- onAbort
2135
- ) {
2136
- var this$1 = this;
2137
-
2138
- var route;
2139
- try {
2140
- route = this.router.match(location, this.current);
2141
- } catch (e) {
2142
- this.errorCbs.forEach(function (cb) {
2143
- cb(e);
2144
- });
2145
- // Exception should still be thrown
2146
- throw e
2147
- }
2148
- this.confirmTransition(
2149
- route,
2150
- function () {
2151
- var prev = this$1.current;
2152
- this$1.updateRoute(route);
2153
- onComplete && onComplete(route);
2154
- this$1.ensureURL();
2155
- this$1.router.afterHooks.forEach(function (hook) {
2156
- hook && hook(route, prev);
2157
- });
2158
-
2159
- // fire ready cbs once
2160
- if (!this$1.ready) {
2161
- this$1.ready = true;
2162
- this$1.readyCbs.forEach(function (cb) {
2163
- cb(route);
2164
- });
2165
- }
2166
- },
2167
- function (err) {
2168
- if (onAbort) {
2169
- onAbort(err);
2170
- }
2171
- if (err && !this$1.ready) {
2172
- this$1.ready = true;
2173
- // Initial redirection should still trigger the onReady onSuccess
2174
- if (!isNavigationFailure(err, NavigationFailureType.redirected)) {
2175
- this$1.readyErrorCbs.forEach(function (cb) {
2176
- cb(err);
2177
- });
2178
- } else {
2179
- this$1.readyCbs.forEach(function (cb) {
2180
- cb(route);
2181
- });
2182
- }
2183
- }
2184
- }
2185
- );
2186
- };
2187
-
2188
- History.prototype.confirmTransition = function confirmTransition (route, onComplete, onAbort) {
2189
- var this$1 = this;
2190
-
2191
- var current = this.current;
2192
- var abort = function (err) {
2193
- // changed after adding errors before that change,
2194
- // redirect and aborted navigation would produce an err == null
2195
- if (!isNavigationFailure(err) && isError(err)) {
2196
- if (this$1.errorCbs.length) {
2197
- this$1.errorCbs.forEach(function (cb) {
2198
- cb(err);
2199
- });
2200
- } else {
2201
- warn(false, 'uncaught error during route navigation:');
2202
- console.error(err);
2203
- }
2204
- }
2205
- onAbort && onAbort(err);
2206
- };
2207
- var lastRouteIndex = route.matched.length - 1;
2208
- var lastCurrentIndex = current.matched.length - 1;
2209
- if (
2210
- isSameRoute(route, current) &&
2211
- // in the case the route map has been dynamically appended to
2212
- lastRouteIndex === lastCurrentIndex &&
2213
- route.matched[lastRouteIndex] === current.matched[lastCurrentIndex]
2214
- ) {
2215
- this.ensureURL();
2216
- return abort(createNavigationDuplicatedError(current, route))
2217
- }
2218
-
2219
- var ref = resolveQueue(
2220
- this.current.matched,
2221
- route.matched
2222
- );
2223
- var updated = ref.updated;
2224
- var deactivated = ref.deactivated;
2225
- var activated = ref.activated;
2226
-
2227
- var queue = [].concat(
2228
- // in-component leave guards
2229
- extractLeaveGuards(deactivated),
2230
- // global before hooks
2231
- this.router.beforeHooks,
2232
- // in-component update hooks
2233
- extractUpdateHooks(updated),
2234
- // in-config enter guards
2235
- activated.map(function (m) { return m.beforeEnter; }),
2236
- // async components
2237
- resolveAsyncComponents(activated)
2238
- );
2239
-
2240
- this.pending = route;
2241
- var iterator = function (hook, next) {
2242
- if (this$1.pending !== route) {
2243
- return abort(createNavigationCancelledError(current, route))
2244
- }
2245
- try {
2246
- hook(route, current, function (to) {
2247
- if (to === false) {
2248
- // next(false) -> abort navigation, ensure current URL
2249
- this$1.ensureURL(true);
2250
- abort(createNavigationAbortedError(current, route));
2251
- } else if (isError(to)) {
2252
- this$1.ensureURL(true);
2253
- abort(to);
2254
- } else if (
2255
- typeof to === 'string' ||
2256
- (typeof to === 'object' &&
2257
- (typeof to.path === 'string' || typeof to.name === 'string'))
2258
- ) {
2259
- // next('/') or next({ path: '/' }) -> redirect
2260
- abort(createNavigationRedirectedError(current, route));
2261
- if (typeof to === 'object' && to.replace) {
2262
- this$1.replace(to);
2263
- } else {
2264
- this$1.push(to);
2265
- }
2266
- } else {
2267
- // confirm transition and pass on the value
2268
- next(to);
2269
- }
2270
- });
2271
- } catch (e) {
2272
- abort(e);
2273
- }
2274
- };
2275
-
2276
- runQueue(queue, iterator, function () {
2277
- var postEnterCbs = [];
2278
- var isValid = function () { return this$1.current === route; };
2279
- // wait until async components are resolved before
2280
- // extracting in-component enter guards
2281
- var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid);
2282
- var queue = enterGuards.concat(this$1.router.resolveHooks);
2283
- runQueue(queue, iterator, function () {
2284
- if (this$1.pending !== route) {
2285
- return abort(createNavigationCancelledError(current, route))
2286
- }
2287
- this$1.pending = null;
2288
- onComplete(route);
2289
- if (this$1.router.app) {
2290
- this$1.router.app.$nextTick(function () {
2291
- postEnterCbs.forEach(function (cb) {
2292
- cb();
2293
- });
2294
- });
2295
- }
2296
- });
2297
- });
2298
- };
2299
-
2300
- History.prototype.updateRoute = function updateRoute (route) {
2301
- this.current = route;
2302
- this.cb && this.cb(route);
2303
- };
2304
-
2305
- History.prototype.setupListeners = function setupListeners () {
2306
- // Default implementation is empty
2307
- };
2308
-
2309
- History.prototype.teardownListeners = function teardownListeners () {
2310
- this.listeners.forEach(function (cleanupListener) {
2311
- cleanupListener();
2312
- });
2313
- this.listeners = [];
2314
- };
2315
-
2316
- function normalizeBase (base) {
2317
- if (!base) {
2318
- if (inBrowser) {
2319
- // respect <base> tag
2320
- var baseEl = document.querySelector('base');
2321
- base = (baseEl && baseEl.getAttribute('href')) || '/';
2322
- // strip full URL origin
2323
- base = base.replace(/^https?:\/\/[^\/]+/, '');
2324
- } else {
2325
- base = '/';
2326
- }
2327
- }
2328
- // make sure there's the starting slash
2329
- if (base.charAt(0) !== '/') {
2330
- base = '/' + base;
2331
- }
2332
- // remove trailing slash
2333
- return base.replace(/\/$/, '')
2334
- }
2335
-
2336
- function resolveQueue (
2337
- current,
2338
- next
2339
- ) {
2340
- var i;
2341
- var max = Math.max(current.length, next.length);
2342
- for (i = 0; i < max; i++) {
2343
- if (current[i] !== next[i]) {
2344
- break
2345
- }
2346
- }
2347
- return {
2348
- updated: next.slice(0, i),
2349
- activated: next.slice(i),
2350
- deactivated: current.slice(i)
2351
- }
2352
- }
2353
-
2354
- function extractGuards (
2355
- records,
2356
- name,
2357
- bind,
2358
- reverse
2359
- ) {
2360
- var guards = flatMapComponents(records, function (def, instance, match, key) {
2361
- var guard = extractGuard(def, name);
2362
- if (guard) {
2363
- return Array.isArray(guard)
2364
- ? guard.map(function (guard) { return bind(guard, instance, match, key); })
2365
- : bind(guard, instance, match, key)
2366
- }
2367
- });
2368
- return flatten(reverse ? guards.reverse() : guards)
2369
- }
2370
-
2371
- function extractGuard (
2372
- def,
2373
- key
2374
- ) {
2375
- if (typeof def !== 'function') {
2376
- // extend now so that global mixins are applied.
2377
- def = _Kdu.extend(def);
2378
- }
2379
- return def.options[key]
2380
- }
2381
-
2382
- function extractLeaveGuards (deactivated) {
2383
- return extractGuards(deactivated, 'beforeRouteLeave', bindGuard, true)
2384
- }
2385
-
2386
- function extractUpdateHooks (updated) {
2387
- return extractGuards(updated, 'beforeRouteUpdate', bindGuard)
2388
- }
2389
-
2390
- function bindGuard (guard, instance) {
2391
- if (instance) {
2392
- return function boundRouteGuard () {
2393
- return guard.apply(instance, arguments)
2394
- }
2395
- }
2396
- }
2397
-
2398
- function extractEnterGuards (
2399
- activated,
2400
- cbs,
2401
- isValid
2402
- ) {
2403
- return extractGuards(
2404
- activated,
2405
- 'beforeRouteEnter',
2406
- function (guard, _, match, key) {
2407
- return bindEnterGuard(guard, match, key, cbs, isValid)
2408
- }
2409
- )
2410
- }
2411
-
2412
- function bindEnterGuard (
2413
- guard,
2414
- match,
2415
- key,
2416
- cbs,
2417
- isValid
2418
- ) {
2419
- return function routeEnterGuard (to, from, next) {
2420
- return guard(to, from, function (cb) {
2421
- if (typeof cb === 'function') {
2422
- cbs.push(function () {
2423
- // #750
2424
- // if a router-view is wrapped with an out-in transition,
2425
- // the instance may not have been registered at this time.
2426
- // we will need to poll for registration until current route
2427
- // is no longer valid.
2428
- poll(cb, match.instances, key, isValid);
2429
- });
2430
- }
2431
- next(cb);
2432
- })
2433
- }
2434
- }
2435
-
2436
- function poll (
2437
- cb, // somehow flow cannot infer this is a function
2438
- instances,
2439
- key,
2440
- isValid
2441
- ) {
2442
- if (
2443
- instances[key] &&
2444
- !instances[key]._isBeingDestroyed // do not reuse being destroyed instance
2445
- ) {
2446
- cb(instances[key]);
2447
- } else if (isValid()) {
2448
- setTimeout(function () {
2449
- poll(cb, instances, key, isValid);
2450
- }, 16);
2451
- }
2452
- }
2453
-
2454
- /* */
2455
-
2456
- var HTML5History = /*@__PURE__*/(function (History) {
2457
- function HTML5History (router, base) {
2458
- History.call(this, router, base);
2459
-
2460
- this._startLocation = getLocation(this.base);
2461
- }
2462
-
2463
- if ( History ) HTML5History.__proto__ = History;
2464
- HTML5History.prototype = Object.create( History && History.prototype );
2465
- HTML5History.prototype.constructor = HTML5History;
2466
-
2467
- HTML5History.prototype.setupListeners = function setupListeners () {
2468
- var this$1 = this;
2469
-
2470
- if (this.listeners.length > 0) {
2471
- return
2472
- }
2473
-
2474
- var router = this.router;
2475
- var expectScroll = router.options.scrollBehavior;
2476
- var supportsScroll = supportsPushState && expectScroll;
2477
-
2478
- if (supportsScroll) {
2479
- this.listeners.push(setupScroll());
2480
- }
2481
-
2482
- var handleRoutingEvent = function () {
2483
- var current = this$1.current;
2484
-
2485
- // Avoiding first `popstate` event dispatched in some browsers but first
2486
- // history route not updated since async guard at the same time.
2487
- var location = getLocation(this$1.base);
2488
- if (this$1.current === START && location === this$1._startLocation) {
2489
- return
2490
- }
2491
-
2492
- this$1.transitionTo(location, function (route) {
2493
- if (supportsScroll) {
2494
- handleScroll(router, route, current, true);
2495
- }
2496
- });
2497
- };
2498
- window.addEventListener('popstate', handleRoutingEvent);
2499
- this.listeners.push(function () {
2500
- window.removeEventListener('popstate', handleRoutingEvent);
2501
- });
2502
- };
2503
-
2504
- HTML5History.prototype.go = function go (n) {
2505
- window.history.go(n);
2506
- };
2507
-
2508
- HTML5History.prototype.push = function push (location, onComplete, onAbort) {
2509
- var this$1 = this;
2510
-
2511
- var ref = this;
2512
- var fromRoute = ref.current;
2513
- this.transitionTo(location, function (route) {
2514
- pushState(cleanPath(this$1.base + route.fullPath));
2515
- handleScroll(this$1.router, route, fromRoute, false);
2516
- onComplete && onComplete(route);
2517
- }, onAbort);
2518
- };
2519
-
2520
- HTML5History.prototype.replace = function replace (location, onComplete, onAbort) {
2521
- var this$1 = this;
2522
-
2523
- var ref = this;
2524
- var fromRoute = ref.current;
2525
- this.transitionTo(location, function (route) {
2526
- replaceState(cleanPath(this$1.base + route.fullPath));
2527
- handleScroll(this$1.router, route, fromRoute, false);
2528
- onComplete && onComplete(route);
2529
- }, onAbort);
2530
- };
2531
-
2532
- HTML5History.prototype.ensureURL = function ensureURL (push) {
2533
- if (getLocation(this.base) !== this.current.fullPath) {
2534
- var current = cleanPath(this.base + this.current.fullPath);
2535
- push ? pushState(current) : replaceState(current);
2536
- }
2537
- };
2538
-
2539
- HTML5History.prototype.getCurrentLocation = function getCurrentLocation () {
2540
- return getLocation(this.base)
2541
- };
2542
-
2543
- return HTML5History;
2544
- }(History));
2545
-
2546
- function getLocation (base) {
2547
- var path = decodeURI(window.location.pathname);
2548
- if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) {
2549
- path = path.slice(base.length);
2550
- }
2551
- return (path || '/') + window.location.search + window.location.hash
2552
- }
2553
-
2554
- /* */
2555
-
2556
- var HashHistory = /*@__PURE__*/(function (History) {
2557
- function HashHistory (router, base, fallback) {
2558
- History.call(this, router, base);
2559
- // check history fallback deeplinking
2560
- if (fallback && checkFallback(this.base)) {
2561
- return
2562
- }
2563
- ensureSlash();
2564
- }
2565
-
2566
- if ( History ) HashHistory.__proto__ = History;
2567
- HashHistory.prototype = Object.create( History && History.prototype );
2568
- HashHistory.prototype.constructor = HashHistory;
2569
-
2570
- // this is delayed until the app mounts
2571
- // to avoid the hashchange listener being fired too early
2572
- HashHistory.prototype.setupListeners = function setupListeners () {
2573
- var this$1 = this;
2574
-
2575
- if (this.listeners.length > 0) {
2576
- return
2577
- }
2578
-
2579
- var router = this.router;
2580
- var expectScroll = router.options.scrollBehavior;
2581
- var supportsScroll = supportsPushState && expectScroll;
2582
-
2583
- if (supportsScroll) {
2584
- this.listeners.push(setupScroll());
2585
- }
2586
-
2587
- var handleRoutingEvent = function () {
2588
- var current = this$1.current;
2589
- if (!ensureSlash()) {
2590
- return
2591
- }
2592
- this$1.transitionTo(getHash(), function (route) {
2593
- if (supportsScroll) {
2594
- handleScroll(this$1.router, route, current, true);
2595
- }
2596
- if (!supportsPushState) {
2597
- replaceHash(route.fullPath);
2598
- }
2599
- });
2600
- };
2601
- var eventType = supportsPushState ? 'popstate' : 'hashchange';
2602
- window.addEventListener(
2603
- eventType,
2604
- handleRoutingEvent
2605
- );
2606
- this.listeners.push(function () {
2607
- window.removeEventListener(eventType, handleRoutingEvent);
2608
- });
2609
- };
2610
-
2611
- HashHistory.prototype.push = function push (location, onComplete, onAbort) {
2612
- var this$1 = this;
2613
-
2614
- var ref = this;
2615
- var fromRoute = ref.current;
2616
- this.transitionTo(
2617
- location,
2618
- function (route) {
2619
- pushHash(route.fullPath);
2620
- handleScroll(this$1.router, route, fromRoute, false);
2621
- onComplete && onComplete(route);
2622
- },
2623
- onAbort
2624
- );
2625
- };
2626
-
2627
- HashHistory.prototype.replace = function replace (location, onComplete, onAbort) {
2628
- var this$1 = this;
2629
-
2630
- var ref = this;
2631
- var fromRoute = ref.current;
2632
- this.transitionTo(
2633
- location,
2634
- function (route) {
2635
- replaceHash(route.fullPath);
2636
- handleScroll(this$1.router, route, fromRoute, false);
2637
- onComplete && onComplete(route);
2638
- },
2639
- onAbort
2640
- );
2641
- };
2642
-
2643
- HashHistory.prototype.go = function go (n) {
2644
- window.history.go(n);
2645
- };
2646
-
2647
- HashHistory.prototype.ensureURL = function ensureURL (push) {
2648
- var current = this.current.fullPath;
2649
- if (getHash() !== current) {
2650
- push ? pushHash(current) : replaceHash(current);
2651
- }
2652
- };
2653
-
2654
- HashHistory.prototype.getCurrentLocation = function getCurrentLocation () {
2655
- return getHash()
2656
- };
2657
-
2658
- return HashHistory;
2659
- }(History));
2660
-
2661
- function checkFallback (base) {
2662
- var location = getLocation(base);
2663
- if (!/^\/#/.test(location)) {
2664
- window.location.replace(cleanPath(base + '/#' + location));
2665
- return true
2666
- }
2667
- }
2668
-
2669
- function ensureSlash () {
2670
- var path = getHash();
2671
- if (path.charAt(0) === '/') {
2672
- return true
2673
- }
2674
- replaceHash('/' + path);
2675
- return false
2676
- }
2677
-
2678
- function getHash () {
2679
- // We can't use window.location.hash here because it's not
2680
- // consistent across browsers - Firefox will pre-decode it!
2681
- var href = window.location.href;
2682
- var index = href.indexOf('#');
2683
- // empty path
2684
- if (index < 0) { return '' }
2685
-
2686
- href = href.slice(index + 1);
2687
- // decode the hash but not the search or hash
2688
- // as search(query) is already decoded
2689
- var searchIndex = href.indexOf('?');
2690
- if (searchIndex < 0) {
2691
- var hashIndex = href.indexOf('#');
2692
- if (hashIndex > -1) {
2693
- href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex);
2694
- } else { href = decodeURI(href); }
2695
- } else {
2696
- href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex);
2697
- }
2698
-
2699
- return href
2700
- }
2701
-
2702
- function getUrl (path) {
2703
- var href = window.location.href;
2704
- var i = href.indexOf('#');
2705
- var base = i >= 0 ? href.slice(0, i) : href;
2706
- return (base + "#" + path)
2707
- }
2708
-
2709
- function pushHash (path) {
2710
- if (supportsPushState) {
2711
- pushState(getUrl(path));
2712
- } else {
2713
- window.location.hash = path;
2714
- }
2715
- }
2716
-
2717
- function replaceHash (path) {
2718
- if (supportsPushState) {
2719
- replaceState(getUrl(path));
2720
- } else {
2721
- window.location.replace(getUrl(path));
2722
- }
2723
- }
2724
-
2725
- /* */
2726
-
2727
- var AbstractHistory = /*@__PURE__*/(function (History) {
2728
- function AbstractHistory (router, base) {
2729
- History.call(this, router, base);
2730
- this.stack = [];
2731
- this.index = -1;
2732
- }
2733
-
2734
- if ( History ) AbstractHistory.__proto__ = History;
2735
- AbstractHistory.prototype = Object.create( History && History.prototype );
2736
- AbstractHistory.prototype.constructor = AbstractHistory;
2737
-
2738
- AbstractHistory.prototype.push = function push (location, onComplete, onAbort) {
2739
- var this$1 = this;
2740
-
2741
- this.transitionTo(
2742
- location,
2743
- function (route) {
2744
- this$1.stack = this$1.stack.slice(0, this$1.index + 1).concat(route);
2745
- this$1.index++;
2746
- onComplete && onComplete(route);
2747
- },
2748
- onAbort
2749
- );
2750
- };
2751
-
2752
- AbstractHistory.prototype.replace = function replace (location, onComplete, onAbort) {
2753
- var this$1 = this;
2754
-
2755
- this.transitionTo(
2756
- location,
2757
- function (route) {
2758
- this$1.stack = this$1.stack.slice(0, this$1.index).concat(route);
2759
- onComplete && onComplete(route);
2760
- },
2761
- onAbort
2762
- );
2763
- };
2764
-
2765
- AbstractHistory.prototype.go = function go (n) {
2766
- var this$1 = this;
2767
-
2768
- var targetIndex = this.index + n;
2769
- if (targetIndex < 0 || targetIndex >= this.stack.length) {
2770
- return
2771
- }
2772
- var route = this.stack[targetIndex];
2773
- this.confirmTransition(
2774
- route,
2775
- function () {
2776
- this$1.index = targetIndex;
2777
- this$1.updateRoute(route);
2778
- },
2779
- function (err) {
2780
- if (isNavigationFailure(err, NavigationFailureType.duplicated)) {
2781
- this$1.index = targetIndex;
2782
- }
2783
- }
2784
- );
2785
- };
2786
-
2787
- AbstractHistory.prototype.getCurrentLocation = function getCurrentLocation () {
2788
- var current = this.stack[this.stack.length - 1];
2789
- return current ? current.fullPath : '/'
2790
- };
2791
-
2792
- AbstractHistory.prototype.ensureURL = function ensureURL () {
2793
- // noop
2794
- };
2795
-
2796
- return AbstractHistory;
2797
- }(History));
2798
-
2799
- /* */
2800
-
2801
- var KduRouter = function KduRouter (options) {
2802
- if ( options === void 0 ) options = {};
2803
-
2804
- this.app = null;
2805
- this.apps = [];
2806
- this.options = options;
2807
- this.beforeHooks = [];
2808
- this.resolveHooks = [];
2809
- this.afterHooks = [];
2810
- this.matcher = createMatcher(options.routes || [], this);
2811
-
2812
- var mode = options.mode || 'hash';
2813
- this.fallback =
2814
- mode === 'history' && !supportsPushState && options.fallback !== false;
2815
- if (this.fallback) {
2816
- mode = 'hash';
2817
- }
2818
- if (!inBrowser) {
2819
- mode = 'abstract';
2820
- }
2821
- this.mode = mode;
2822
-
2823
- switch (mode) {
2824
- case 'history':
2825
- this.history = new HTML5History(this, options.base);
2826
- break
2827
- case 'hash':
2828
- this.history = new HashHistory(this, options.base, this.fallback);
2829
- break
2830
- case 'abstract':
2831
- this.history = new AbstractHistory(this, options.base);
2832
- break
2833
- default:
2834
- {
2835
- assert(false, ("invalid mode: " + mode));
2836
- }
2837
- }
2838
- };
2839
-
2840
- var prototypeAccessors = { currentRoute: { configurable: true } };
2841
-
2842
- KduRouter.prototype.match = function match (raw, current, redirectedFrom) {
2843
- return this.matcher.match(raw, current, redirectedFrom)
2844
- };
2845
-
2846
- prototypeAccessors.currentRoute.get = function () {
2847
- return this.history && this.history.current
2848
- };
2849
-
2850
- KduRouter.prototype.init = function init (app /* Kdu component instance */) {
2851
- var this$1 = this;
2852
-
2853
-
2854
- assert(
2855
- install.installed,
2856
- "not installed. Make sure to call `Kdu.use(KduRouter)` " +
2857
- "before creating root instance."
2858
- );
2859
-
2860
- this.apps.push(app);
2861
-
2862
- // set up app destroyed handler
2863
- app.$once('hook:destroyed', function () {
2864
- // clean out app from this.apps array once destroyed
2865
- var index = this$1.apps.indexOf(app);
2866
- if (index > -1) { this$1.apps.splice(index, 1); }
2867
- // ensure we still have a main app or null if no apps
2868
- // we do not release the router so it can be reused
2869
- if (this$1.app === app) { this$1.app = this$1.apps[0] || null; }
2870
-
2871
- if (!this$1.app) {
2872
- // clean up event listeners
2873
- this$1.history.teardownListeners();
2874
- }
2875
- });
2876
-
2877
- // main app previously initialized
2878
- // return as we don't need to set up new history listener
2879
- if (this.app) {
2880
- return
2881
- }
2882
-
2883
- this.app = app;
2884
-
2885
- var history = this.history;
2886
-
2887
- if (history instanceof HTML5History || history instanceof HashHistory) {
2888
- var handleInitialScroll = function (routeOrError) {
2889
- var from = history.current;
2890
- var expectScroll = this$1.options.scrollBehavior;
2891
- var supportsScroll = supportsPushState && expectScroll;
2892
-
2893
- if (supportsScroll && 'fullPath' in routeOrError) {
2894
- handleScroll(this$1, routeOrError, from, false);
2895
- }
2896
- };
2897
- var setupListeners = function (routeOrError) {
2898
- history.setupListeners();
2899
- handleInitialScroll(routeOrError);
2900
- };
2901
- history.transitionTo(
2902
- history.getCurrentLocation(),
2903
- setupListeners,
2904
- setupListeners
2905
- );
2906
- }
2907
-
2908
- history.listen(function (route) {
2909
- this$1.apps.forEach(function (app) {
2910
- app._route = route;
2911
- });
2912
- });
2913
- };
2914
-
2915
- KduRouter.prototype.beforeEach = function beforeEach (fn) {
2916
- return registerHook(this.beforeHooks, fn)
2917
- };
2918
-
2919
- KduRouter.prototype.beforeResolve = function beforeResolve (fn) {
2920
- return registerHook(this.resolveHooks, fn)
2921
- };
2922
-
2923
- KduRouter.prototype.afterEach = function afterEach (fn) {
2924
- return registerHook(this.afterHooks, fn)
2925
- };
2926
-
2927
- KduRouter.prototype.onReady = function onReady (cb, errorCb) {
2928
- this.history.onReady(cb, errorCb);
2929
- };
2930
-
2931
- KduRouter.prototype.onError = function onError (errorCb) {
2932
- this.history.onError(errorCb);
2933
- };
2934
-
2935
- KduRouter.prototype.push = function push (location, onComplete, onAbort) {
2936
- var this$1 = this;
2937
-
2938
- // $flow-disable-line
2939
- if (!onComplete && !onAbort && typeof Promise !== 'undefined') {
2940
- return new Promise(function (resolve, reject) {
2941
- this$1.history.push(location, resolve, reject);
2942
- })
2943
- } else {
2944
- this.history.push(location, onComplete, onAbort);
2945
- }
2946
- };
2947
-
2948
- KduRouter.prototype.replace = function replace (location, onComplete, onAbort) {
2949
- var this$1 = this;
2950
-
2951
- // $flow-disable-line
2952
- if (!onComplete && !onAbort && typeof Promise !== 'undefined') {
2953
- return new Promise(function (resolve, reject) {
2954
- this$1.history.replace(location, resolve, reject);
2955
- })
2956
- } else {
2957
- this.history.replace(location, onComplete, onAbort);
2958
- }
2959
- };
2960
-
2961
- KduRouter.prototype.go = function go (n) {
2962
- this.history.go(n);
2963
- };
2964
-
2965
- KduRouter.prototype.back = function back () {
2966
- this.go(-1);
2967
- };
2968
-
2969
- KduRouter.prototype.forward = function forward () {
2970
- this.go(1);
2971
- };
2972
-
2973
- KduRouter.prototype.getMatchedComponents = function getMatchedComponents (to) {
2974
- var route = to
2975
- ? to.matched
2976
- ? to
2977
- : this.resolve(to).route
2978
- : this.currentRoute;
2979
- if (!route) {
2980
- return []
2981
- }
2982
- return [].concat.apply(
2983
- [],
2984
- route.matched.map(function (m) {
2985
- return Object.keys(m.components).map(function (key) {
2986
- return m.components[key]
2987
- })
2988
- })
2989
- )
2990
- };
2991
-
2992
- KduRouter.prototype.resolve = function resolve (
2993
- to,
2994
- current,
2995
- append
2996
- ) {
2997
- current = current || this.history.current;
2998
- var location = normalizeLocation(to, current, append, this);
2999
- var route = this.match(location, current);
3000
- var fullPath = route.redirectedFrom || route.fullPath;
3001
- var base = this.history.base;
3002
- var href = createHref(base, fullPath, this.mode);
3003
- return {
3004
- location: location,
3005
- route: route,
3006
- href: href,
3007
- // for backwards compat
3008
- normalizedTo: location,
3009
- resolved: route
3010
- }
3011
- };
3012
-
3013
- KduRouter.prototype.addRoutes = function addRoutes (routes) {
3014
- this.matcher.addRoutes(routes);
3015
- if (this.history.current !== START) {
3016
- this.history.transitionTo(this.history.getCurrentLocation());
3017
- }
3018
- };
3019
-
3020
- Object.defineProperties( KduRouter.prototype, prototypeAccessors );
3021
-
3022
- function registerHook (list, fn) {
3023
- list.push(fn);
3024
- return function () {
3025
- var i = list.indexOf(fn);
3026
- if (i > -1) { list.splice(i, 1); }
3027
- }
3028
- }
3029
-
3030
- function createHref (base, fullPath, mode) {
3031
- var path = mode === 'hash' ? '#' + fullPath : fullPath;
3032
- return base ? cleanPath(base + '/' + path) : path
3033
- }
3034
-
3035
- KduRouter.install = install;
3036
- KduRouter.version = '3.4.0-beta.0';
3037
- KduRouter.isNavigationFailure = isNavigationFailure;
3038
- KduRouter.NavigationFailureType = NavigationFailureType;
3039
-
3040
- if (inBrowser && window.Kdu) {
3041
- window.Kdu.use(KduRouter);
3042
- }
3043
-
3044
- return KduRouter;
3045
-
3046
- })));