vue-router.esm.js 76 KB

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