UNPKG

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