vue-router.js 80 KB

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