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