vue-router.common.js 76 KB

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