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