f_000004 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653
  1. import {
  2. setupDevtoolsPlugin
  3. } from "/node_modules/.vite/deps/chunk-5OBJFL24.js?v=9548b9c3";
  4. import {
  5. computed,
  6. defineComponent,
  7. getCurrentInstance,
  8. h,
  9. inject,
  10. nextTick,
  11. onActivated,
  12. onDeactivated,
  13. onUnmounted,
  14. provide,
  15. reactive,
  16. ref,
  17. shallowRef,
  18. unref,
  19. watch,
  20. watchEffect
  21. } from "/node_modules/.vite/deps/chunk-LJEY6MVM.js?v=9548b9c3";
  22. import "/node_modules/.vite/deps/chunk-WQG2LZMB.js?v=9548b9c3";
  23. // node_modules/vue-router/dist/vue-router.mjs
  24. var isBrowser = typeof window !== "undefined";
  25. function isESModule(obj) {
  26. return obj.__esModule || obj[Symbol.toStringTag] === "Module";
  27. }
  28. var assign = Object.assign;
  29. function applyToParams(fn, params) {
  30. const newParams = {};
  31. for (const key in params) {
  32. const value = params[key];
  33. newParams[key] = isArray(value) ? value.map(fn) : fn(value);
  34. }
  35. return newParams;
  36. }
  37. var noop = () => {
  38. };
  39. var isArray = Array.isArray;
  40. function warn(msg) {
  41. const args = Array.from(arguments).slice(1);
  42. console.warn.apply(console, ["[Vue Router warn]: " + msg].concat(args));
  43. }
  44. var TRAILING_SLASH_RE = /\/$/;
  45. var removeTrailingSlash = (path) => path.replace(TRAILING_SLASH_RE, "");
  46. function parseURL(parseQuery2, location2, currentLocation = "/") {
  47. let path, query = {}, searchString = "", hash = "";
  48. const hashPos = location2.indexOf("#");
  49. let searchPos = location2.indexOf("?");
  50. if (hashPos < searchPos && hashPos >= 0) {
  51. searchPos = -1;
  52. }
  53. if (searchPos > -1) {
  54. path = location2.slice(0, searchPos);
  55. searchString = location2.slice(searchPos + 1, hashPos > -1 ? hashPos : location2.length);
  56. query = parseQuery2(searchString);
  57. }
  58. if (hashPos > -1) {
  59. path = path || location2.slice(0, hashPos);
  60. hash = location2.slice(hashPos, location2.length);
  61. }
  62. path = resolveRelativePath(path != null ? path : location2, currentLocation);
  63. return {
  64. fullPath: path + (searchString && "?") + searchString + hash,
  65. path,
  66. query,
  67. hash
  68. };
  69. }
  70. function stringifyURL(stringifyQuery2, location2) {
  71. const query = location2.query ? stringifyQuery2(location2.query) : "";
  72. return location2.path + (query && "?") + query + (location2.hash || "");
  73. }
  74. function stripBase(pathname, base) {
  75. if (!base || !pathname.toLowerCase().startsWith(base.toLowerCase()))
  76. return pathname;
  77. return pathname.slice(base.length) || "/";
  78. }
  79. function isSameRouteLocation(stringifyQuery2, a, b) {
  80. const aLastIndex = a.matched.length - 1;
  81. const bLastIndex = b.matched.length - 1;
  82. return aLastIndex > -1 && aLastIndex === bLastIndex && isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) && isSameRouteLocationParams(a.params, b.params) && stringifyQuery2(a.query) === stringifyQuery2(b.query) && a.hash === b.hash;
  83. }
  84. function isSameRouteRecord(a, b) {
  85. return (a.aliasOf || a) === (b.aliasOf || b);
  86. }
  87. function isSameRouteLocationParams(a, b) {
  88. if (Object.keys(a).length !== Object.keys(b).length)
  89. return false;
  90. for (const key in a) {
  91. if (!isSameRouteLocationParamsValue(a[key], b[key]))
  92. return false;
  93. }
  94. return true;
  95. }
  96. function isSameRouteLocationParamsValue(a, b) {
  97. return isArray(a) ? isEquivalentArray(a, b) : isArray(b) ? isEquivalentArray(b, a) : a === b;
  98. }
  99. function isEquivalentArray(a, b) {
  100. return isArray(b) ? a.length === b.length && a.every((value, i) => value === b[i]) : a.length === 1 && a[0] === b;
  101. }
  102. function resolveRelativePath(to, from) {
  103. if (to.startsWith("/"))
  104. return to;
  105. if (!from.startsWith("/")) {
  106. warn(`Cannot resolve a relative location without an absolute path. Trying to resolve "${to}" from "${from}". It should look like "/${from}".`);
  107. return to;
  108. }
  109. if (!to)
  110. return from;
  111. const fromSegments = from.split("/");
  112. const toSegments = to.split("/");
  113. let position = fromSegments.length - 1;
  114. let toPosition;
  115. let segment;
  116. for (toPosition = 0; toPosition < toSegments.length; toPosition++) {
  117. segment = toSegments[toPosition];
  118. if (segment === ".")
  119. continue;
  120. if (segment === "..") {
  121. if (position > 1)
  122. position--;
  123. } else
  124. break;
  125. }
  126. return fromSegments.slice(0, position).join("/") + "/" + toSegments.slice(toPosition - (toPosition === toSegments.length ? 1 : 0)).join("/");
  127. }
  128. var NavigationType;
  129. (function(NavigationType2) {
  130. NavigationType2["pop"] = "pop";
  131. NavigationType2["push"] = "push";
  132. })(NavigationType || (NavigationType = {}));
  133. var NavigationDirection;
  134. (function(NavigationDirection2) {
  135. NavigationDirection2["back"] = "back";
  136. NavigationDirection2["forward"] = "forward";
  137. NavigationDirection2["unknown"] = "";
  138. })(NavigationDirection || (NavigationDirection = {}));
  139. var START = "";
  140. function normalizeBase(base) {
  141. if (!base) {
  142. if (isBrowser) {
  143. const baseEl = document.querySelector("base");
  144. base = baseEl && baseEl.getAttribute("href") || "/";
  145. base = base.replace(/^\w+:\/\/[^\/]+/, "");
  146. } else {
  147. base = "/";
  148. }
  149. }
  150. if (base[0] !== "/" && base[0] !== "#")
  151. base = "/" + base;
  152. return removeTrailingSlash(base);
  153. }
  154. var BEFORE_HASH_RE = /^[^#]+#/;
  155. function createHref(base, location2) {
  156. return base.replace(BEFORE_HASH_RE, "#") + location2;
  157. }
  158. function getElementPosition(el, offset) {
  159. const docRect = document.documentElement.getBoundingClientRect();
  160. const elRect = el.getBoundingClientRect();
  161. return {
  162. behavior: offset.behavior,
  163. left: elRect.left - docRect.left - (offset.left || 0),
  164. top: elRect.top - docRect.top - (offset.top || 0)
  165. };
  166. }
  167. var computeScrollPosition = () => ({
  168. left: window.pageXOffset,
  169. top: window.pageYOffset
  170. });
  171. function scrollToPosition(position) {
  172. let scrollToOptions;
  173. if ("el" in position) {
  174. const positionEl = position.el;
  175. const isIdSelector = typeof positionEl === "string" && positionEl.startsWith("#");
  176. if (typeof position.el === "string") {
  177. if (!isIdSelector || !document.getElementById(position.el.slice(1))) {
  178. try {
  179. const foundEl = document.querySelector(position.el);
  180. if (isIdSelector && foundEl) {
  181. warn(`The selector "${position.el}" should be passed as "el: document.querySelector('${position.el}')" because it starts with "#".`);
  182. return;
  183. }
  184. } catch (err) {
  185. warn(`The selector "${position.el}" is invalid. If you are using an id selector, make sure to escape it. You can find more information about escaping characters in selectors at https://mathiasbynens.be/notes/css-escapes or use CSS.escape (https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape).`);
  186. return;
  187. }
  188. }
  189. }
  190. const el = typeof positionEl === "string" ? isIdSelector ? document.getElementById(positionEl.slice(1)) : document.querySelector(positionEl) : positionEl;
  191. if (!el) {
  192. warn(`Couldn't find element using selector "${position.el}" returned by scrollBehavior.`);
  193. return;
  194. }
  195. scrollToOptions = getElementPosition(el, position);
  196. } else {
  197. scrollToOptions = position;
  198. }
  199. if ("scrollBehavior" in document.documentElement.style)
  200. window.scrollTo(scrollToOptions);
  201. else {
  202. window.scrollTo(scrollToOptions.left != null ? scrollToOptions.left : window.pageXOffset, scrollToOptions.top != null ? scrollToOptions.top : window.pageYOffset);
  203. }
  204. }
  205. function getScrollKey(path, delta) {
  206. const position = history.state ? history.state.position - delta : -1;
  207. return position + path;
  208. }
  209. var scrollPositions = /* @__PURE__ */ new Map();
  210. function saveScrollPosition(key, scrollPosition) {
  211. scrollPositions.set(key, scrollPosition);
  212. }
  213. function getSavedScrollPosition(key) {
  214. const scroll = scrollPositions.get(key);
  215. scrollPositions.delete(key);
  216. return scroll;
  217. }
  218. var createBaseLocation = () => location.protocol + "//" + location.host;
  219. function createCurrentLocation(base, location2) {
  220. const { pathname, search, hash } = location2;
  221. const hashPos = base.indexOf("#");
  222. if (hashPos > -1) {
  223. let slicePos = hash.includes(base.slice(hashPos)) ? base.slice(hashPos).length : 1;
  224. let pathFromHash = hash.slice(slicePos);
  225. if (pathFromHash[0] !== "/")
  226. pathFromHash = "/" + pathFromHash;
  227. return stripBase(pathFromHash, "");
  228. }
  229. const path = stripBase(pathname, base);
  230. return path + search + hash;
  231. }
  232. function useHistoryListeners(base, historyState, currentLocation, replace) {
  233. let listeners = [];
  234. let teardowns = [];
  235. let pauseState = null;
  236. const popStateHandler = ({ state }) => {
  237. const to = createCurrentLocation(base, location);
  238. const from = currentLocation.value;
  239. const fromState = historyState.value;
  240. let delta = 0;
  241. if (state) {
  242. currentLocation.value = to;
  243. historyState.value = state;
  244. if (pauseState && pauseState === from) {
  245. pauseState = null;
  246. return;
  247. }
  248. delta = fromState ? state.position - fromState.position : 0;
  249. } else {
  250. replace(to);
  251. }
  252. listeners.forEach((listener) => {
  253. listener(currentLocation.value, from, {
  254. delta,
  255. type: NavigationType.pop,
  256. direction: delta ? delta > 0 ? NavigationDirection.forward : NavigationDirection.back : NavigationDirection.unknown
  257. });
  258. });
  259. };
  260. function pauseListeners() {
  261. pauseState = currentLocation.value;
  262. }
  263. function listen(callback) {
  264. listeners.push(callback);
  265. const teardown = () => {
  266. const index = listeners.indexOf(callback);
  267. if (index > -1)
  268. listeners.splice(index, 1);
  269. };
  270. teardowns.push(teardown);
  271. return teardown;
  272. }
  273. function beforeUnloadListener() {
  274. const { history: history2 } = window;
  275. if (!history2.state)
  276. return;
  277. history2.replaceState(assign({}, history2.state, { scroll: computeScrollPosition() }), "");
  278. }
  279. function destroy() {
  280. for (const teardown of teardowns)
  281. teardown();
  282. teardowns = [];
  283. window.removeEventListener("popstate", popStateHandler);
  284. window.removeEventListener("beforeunload", beforeUnloadListener);
  285. }
  286. window.addEventListener("popstate", popStateHandler);
  287. window.addEventListener("beforeunload", beforeUnloadListener);
  288. return {
  289. pauseListeners,
  290. listen,
  291. destroy
  292. };
  293. }
  294. function buildState(back, current, forward, replaced = false, computeScroll = false) {
  295. return {
  296. back,
  297. current,
  298. forward,
  299. replaced,
  300. position: window.history.length,
  301. scroll: computeScroll ? computeScrollPosition() : null
  302. };
  303. }
  304. function useHistoryStateNavigation(base) {
  305. const { history: history2, location: location2 } = window;
  306. const currentLocation = {
  307. value: createCurrentLocation(base, location2)
  308. };
  309. const historyState = { value: history2.state };
  310. if (!historyState.value) {
  311. changeLocation(currentLocation.value, {
  312. back: null,
  313. current: currentLocation.value,
  314. forward: null,
  315. // the length is off by one, we need to decrease it
  316. position: history2.length - 1,
  317. replaced: true,
  318. // don't add a scroll as the user may have an anchor, and we want
  319. // scrollBehavior to be triggered without a saved position
  320. scroll: null
  321. }, true);
  322. }
  323. function changeLocation(to, state, replace2) {
  324. const hashIndex = base.indexOf("#");
  325. const url = hashIndex > -1 ? (location2.host && document.querySelector("base") ? base : base.slice(hashIndex)) + to : createBaseLocation() + base + to;
  326. try {
  327. history2[replace2 ? "replaceState" : "pushState"](state, "", url);
  328. historyState.value = state;
  329. } catch (err) {
  330. if (true) {
  331. warn("Error with push/replace State", err);
  332. } else {
  333. console.error(err);
  334. }
  335. location2[replace2 ? "replace" : "assign"](url);
  336. }
  337. }
  338. function replace(to, data) {
  339. const state = assign({}, history2.state, buildState(
  340. historyState.value.back,
  341. // keep back and forward entries but override current position
  342. to,
  343. historyState.value.forward,
  344. true
  345. ), data, { position: historyState.value.position });
  346. changeLocation(to, state, true);
  347. currentLocation.value = to;
  348. }
  349. function push(to, data) {
  350. const currentState = assign(
  351. {},
  352. // use current history state to gracefully handle a wrong call to
  353. // history.replaceState
  354. // https://github.com/vuejs/router/issues/366
  355. historyState.value,
  356. history2.state,
  357. {
  358. forward: to,
  359. scroll: computeScrollPosition()
  360. }
  361. );
  362. if (!history2.state) {
  363. warn(`history.state seems to have been manually replaced without preserving the necessary values. Make sure to preserve existing history state if you are manually calling history.replaceState:
  364. history.replaceState(history.state, '', url)
  365. You can find more information at https://next.router.vuejs.org/guide/migration/#usage-of-history-state.`);
  366. }
  367. changeLocation(currentState.current, currentState, true);
  368. const state = assign({}, buildState(currentLocation.value, to, null), { position: currentState.position + 1 }, data);
  369. changeLocation(to, state, false);
  370. currentLocation.value = to;
  371. }
  372. return {
  373. location: currentLocation,
  374. state: historyState,
  375. push,
  376. replace
  377. };
  378. }
  379. function createWebHistory(base) {
  380. base = normalizeBase(base);
  381. const historyNavigation = useHistoryStateNavigation(base);
  382. const historyListeners = useHistoryListeners(base, historyNavigation.state, historyNavigation.location, historyNavigation.replace);
  383. function go(delta, triggerListeners = true) {
  384. if (!triggerListeners)
  385. historyListeners.pauseListeners();
  386. history.go(delta);
  387. }
  388. const routerHistory = assign({
  389. // it's overridden right after
  390. location: "",
  391. base,
  392. go,
  393. createHref: createHref.bind(null, base)
  394. }, historyNavigation, historyListeners);
  395. Object.defineProperty(routerHistory, "location", {
  396. enumerable: true,
  397. get: () => historyNavigation.location.value
  398. });
  399. Object.defineProperty(routerHistory, "state", {
  400. enumerable: true,
  401. get: () => historyNavigation.state.value
  402. });
  403. return routerHistory;
  404. }
  405. function createMemoryHistory(base = "") {
  406. let listeners = [];
  407. let queue = [START];
  408. let position = 0;
  409. base = normalizeBase(base);
  410. function setLocation(location2) {
  411. position++;
  412. if (position === queue.length) {
  413. queue.push(location2);
  414. } else {
  415. queue.splice(position);
  416. queue.push(location2);
  417. }
  418. }
  419. function triggerListeners(to, from, { direction, delta }) {
  420. const info = {
  421. direction,
  422. delta,
  423. type: NavigationType.pop
  424. };
  425. for (const callback of listeners) {
  426. callback(to, from, info);
  427. }
  428. }
  429. const routerHistory = {
  430. // rewritten by Object.defineProperty
  431. location: START,
  432. // TODO: should be kept in queue
  433. state: {},
  434. base,
  435. createHref: createHref.bind(null, base),
  436. replace(to) {
  437. queue.splice(position--, 1);
  438. setLocation(to);
  439. },
  440. push(to, data) {
  441. setLocation(to);
  442. },
  443. listen(callback) {
  444. listeners.push(callback);
  445. return () => {
  446. const index = listeners.indexOf(callback);
  447. if (index > -1)
  448. listeners.splice(index, 1);
  449. };
  450. },
  451. destroy() {
  452. listeners = [];
  453. queue = [START];
  454. position = 0;
  455. },
  456. go(delta, shouldTrigger = true) {
  457. const from = this.location;
  458. const direction = (
  459. // we are considering delta === 0 going forward, but in abstract mode
  460. // using 0 for the delta doesn't make sense like it does in html5 where
  461. // it reloads the page
  462. delta < 0 ? NavigationDirection.back : NavigationDirection.forward
  463. );
  464. position = Math.max(0, Math.min(position + delta, queue.length - 1));
  465. if (shouldTrigger) {
  466. triggerListeners(this.location, from, {
  467. direction,
  468. delta
  469. });
  470. }
  471. }
  472. };
  473. Object.defineProperty(routerHistory, "location", {
  474. enumerable: true,
  475. get: () => queue[position]
  476. });
  477. return routerHistory;
  478. }
  479. function createWebHashHistory(base) {
  480. base = location.host ? base || location.pathname + location.search : "";
  481. if (!base.includes("#"))
  482. base += "#";
  483. if (!base.endsWith("#/") && !base.endsWith("#")) {
  484. warn(`A hash base must end with a "#":
  485. "${base}" should be "${base.replace(/#.*$/, "#")}".`);
  486. }
  487. return createWebHistory(base);
  488. }
  489. function isRouteLocation(route) {
  490. return typeof route === "string" || route && typeof route === "object";
  491. }
  492. function isRouteName(name) {
  493. return typeof name === "string" || typeof name === "symbol";
  494. }
  495. var START_LOCATION_NORMALIZED = {
  496. path: "/",
  497. name: void 0,
  498. params: {},
  499. query: {},
  500. hash: "",
  501. fullPath: "/",
  502. matched: [],
  503. meta: {},
  504. redirectedFrom: void 0
  505. };
  506. var NavigationFailureSymbol = Symbol(true ? "navigation failure" : "");
  507. var NavigationFailureType;
  508. (function(NavigationFailureType2) {
  509. NavigationFailureType2[NavigationFailureType2["aborted"] = 4] = "aborted";
  510. NavigationFailureType2[NavigationFailureType2["cancelled"] = 8] = "cancelled";
  511. NavigationFailureType2[NavigationFailureType2["duplicated"] = 16] = "duplicated";
  512. })(NavigationFailureType || (NavigationFailureType = {}));
  513. var ErrorTypeMessages = {
  514. [
  515. 1
  516. /* ErrorTypes.MATCHER_NOT_FOUND */
  517. ]({ location: location2, currentLocation }) {
  518. return `No match for
  519. ${JSON.stringify(location2)}${currentLocation ? "\nwhile being at\n" + JSON.stringify(currentLocation) : ""}`;
  520. },
  521. [
  522. 2
  523. /* ErrorTypes.NAVIGATION_GUARD_REDIRECT */
  524. ]({ from, to }) {
  525. return `Redirected from "${from.fullPath}" to "${stringifyRoute(to)}" via a navigation guard.`;
  526. },
  527. [
  528. 4
  529. /* ErrorTypes.NAVIGATION_ABORTED */
  530. ]({ from, to }) {
  531. return `Navigation aborted from "${from.fullPath}" to "${to.fullPath}" via a navigation guard.`;
  532. },
  533. [
  534. 8
  535. /* ErrorTypes.NAVIGATION_CANCELLED */
  536. ]({ from, to }) {
  537. return `Navigation cancelled from "${from.fullPath}" to "${to.fullPath}" with a new navigation.`;
  538. },
  539. [
  540. 16
  541. /* ErrorTypes.NAVIGATION_DUPLICATED */
  542. ]({ from, to }) {
  543. return `Avoided redundant navigation to current location: "${from.fullPath}".`;
  544. }
  545. };
  546. function createRouterError(type, params) {
  547. if (true) {
  548. return assign(new Error(ErrorTypeMessages[type](params)), {
  549. type,
  550. [NavigationFailureSymbol]: true
  551. }, params);
  552. } else {
  553. return assign(new Error(), {
  554. type,
  555. [NavigationFailureSymbol]: true
  556. }, params);
  557. }
  558. }
  559. function isNavigationFailure(error, type) {
  560. return error instanceof Error && NavigationFailureSymbol in error && (type == null || !!(error.type & type));
  561. }
  562. var propertiesToLog = ["params", "query", "hash"];
  563. function stringifyRoute(to) {
  564. if (typeof to === "string")
  565. return to;
  566. if ("path" in to)
  567. return to.path;
  568. const location2 = {};
  569. for (const key of propertiesToLog) {
  570. if (key in to)
  571. location2[key] = to[key];
  572. }
  573. return JSON.stringify(location2, null, 2);
  574. }
  575. var BASE_PARAM_PATTERN = "[^/]+?";
  576. var BASE_PATH_PARSER_OPTIONS = {
  577. sensitive: false,
  578. strict: false,
  579. start: true,
  580. end: true
  581. };
  582. var REGEX_CHARS_RE = /[.+*?^${}()[\]/\\]/g;
  583. function tokensToParser(segments, extraOptions) {
  584. const options = assign({}, BASE_PATH_PARSER_OPTIONS, extraOptions);
  585. const score = [];
  586. let pattern = options.start ? "^" : "";
  587. const keys = [];
  588. for (const segment of segments) {
  589. const segmentScores = segment.length ? [] : [
  590. 90
  591. /* PathScore.Root */
  592. ];
  593. if (options.strict && !segment.length)
  594. pattern += "/";
  595. for (let tokenIndex = 0; tokenIndex < segment.length; tokenIndex++) {
  596. const token = segment[tokenIndex];
  597. let subSegmentScore = 40 + (options.sensitive ? 0.25 : 0);
  598. if (token.type === 0) {
  599. if (!tokenIndex)
  600. pattern += "/";
  601. pattern += token.value.replace(REGEX_CHARS_RE, "\\$&");
  602. subSegmentScore += 40;
  603. } else if (token.type === 1) {
  604. const { value, repeatable, optional, regexp } = token;
  605. keys.push({
  606. name: value,
  607. repeatable,
  608. optional
  609. });
  610. const re2 = regexp ? regexp : BASE_PARAM_PATTERN;
  611. if (re2 !== BASE_PARAM_PATTERN) {
  612. subSegmentScore += 10;
  613. try {
  614. new RegExp(`(${re2})`);
  615. } catch (err) {
  616. throw new Error(`Invalid custom RegExp for param "${value}" (${re2}): ` + err.message);
  617. }
  618. }
  619. let subPattern = repeatable ? `((?:${re2})(?:/(?:${re2}))*)` : `(${re2})`;
  620. if (!tokenIndex)
  621. subPattern = // avoid an optional / if there are more segments e.g. /:p?-static
  622. // or /:p?-:p2
  623. optional && segment.length < 2 ? `(?:/${subPattern})` : "/" + subPattern;
  624. if (optional)
  625. subPattern += "?";
  626. pattern += subPattern;
  627. subSegmentScore += 20;
  628. if (optional)
  629. subSegmentScore += -8;
  630. if (repeatable)
  631. subSegmentScore += -20;
  632. if (re2 === ".*")
  633. subSegmentScore += -50;
  634. }
  635. segmentScores.push(subSegmentScore);
  636. }
  637. score.push(segmentScores);
  638. }
  639. if (options.strict && options.end) {
  640. const i = score.length - 1;
  641. score[i][score[i].length - 1] += 0.7000000000000001;
  642. }
  643. if (!options.strict)
  644. pattern += "/?";
  645. if (options.end)
  646. pattern += "$";
  647. else if (options.strict)
  648. pattern += "(?:/|$)";
  649. const re = new RegExp(pattern, options.sensitive ? "" : "i");
  650. function parse(path) {
  651. const match = path.match(re);
  652. const params = {};
  653. if (!match)
  654. return null;
  655. for (let i = 1; i < match.length; i++) {
  656. const value = match[i] || "";
  657. const key = keys[i - 1];
  658. params[key.name] = value && key.repeatable ? value.split("/") : value;
  659. }
  660. return params;
  661. }
  662. function stringify(params) {
  663. let path = "";
  664. let avoidDuplicatedSlash = false;
  665. for (const segment of segments) {
  666. if (!avoidDuplicatedSlash || !path.endsWith("/"))
  667. path += "/";
  668. avoidDuplicatedSlash = false;
  669. for (const token of segment) {
  670. if (token.type === 0) {
  671. path += token.value;
  672. } else if (token.type === 1) {
  673. const { value, repeatable, optional } = token;
  674. const param = value in params ? params[value] : "";
  675. if (isArray(param) && !repeatable) {
  676. throw new Error(`Provided param "${value}" is an array but it is not repeatable (* or + modifiers)`);
  677. }
  678. const text = isArray(param) ? param.join("/") : param;
  679. if (!text) {
  680. if (optional) {
  681. if (segment.length < 2) {
  682. if (path.endsWith("/"))
  683. path = path.slice(0, -1);
  684. else
  685. avoidDuplicatedSlash = true;
  686. }
  687. } else
  688. throw new Error(`Missing required param "${value}"`);
  689. }
  690. path += text;
  691. }
  692. }
  693. }
  694. return path || "/";
  695. }
  696. return {
  697. re,
  698. score,
  699. keys,
  700. parse,
  701. stringify
  702. };
  703. }
  704. function compareScoreArray(a, b) {
  705. let i = 0;
  706. while (i < a.length && i < b.length) {
  707. const diff = b[i] - a[i];
  708. if (diff)
  709. return diff;
  710. i++;
  711. }
  712. if (a.length < b.length) {
  713. return a.length === 1 && a[0] === 40 + 40 ? -1 : 1;
  714. } else if (a.length > b.length) {
  715. return b.length === 1 && b[0] === 40 + 40 ? 1 : -1;
  716. }
  717. return 0;
  718. }
  719. function comparePathParserScore(a, b) {
  720. let i = 0;
  721. const aScore = a.score;
  722. const bScore = b.score;
  723. while (i < aScore.length && i < bScore.length) {
  724. const comp = compareScoreArray(aScore[i], bScore[i]);
  725. if (comp)
  726. return comp;
  727. i++;
  728. }
  729. if (Math.abs(bScore.length - aScore.length) === 1) {
  730. if (isLastScoreNegative(aScore))
  731. return 1;
  732. if (isLastScoreNegative(bScore))
  733. return -1;
  734. }
  735. return bScore.length - aScore.length;
  736. }
  737. function isLastScoreNegative(score) {
  738. const last = score[score.length - 1];
  739. return score.length > 0 && last[last.length - 1] < 0;
  740. }
  741. var ROOT_TOKEN = {
  742. type: 0,
  743. value: ""
  744. };
  745. var VALID_PARAM_RE = /[a-zA-Z0-9_]/;
  746. function tokenizePath(path) {
  747. if (!path)
  748. return [[]];
  749. if (path === "/")
  750. return [[ROOT_TOKEN]];
  751. if (!path.startsWith("/")) {
  752. throw new Error(true ? `Route paths should start with a "/": "${path}" should be "/${path}".` : `Invalid path "${path}"`);
  753. }
  754. function crash(message) {
  755. throw new Error(`ERR (${state})/"${buffer}": ${message}`);
  756. }
  757. let state = 0;
  758. let previousState = state;
  759. const tokens = [];
  760. let segment;
  761. function finalizeSegment() {
  762. if (segment)
  763. tokens.push(segment);
  764. segment = [];
  765. }
  766. let i = 0;
  767. let char;
  768. let buffer = "";
  769. let customRe = "";
  770. function consumeBuffer() {
  771. if (!buffer)
  772. return;
  773. if (state === 0) {
  774. segment.push({
  775. type: 0,
  776. value: buffer
  777. });
  778. } else if (state === 1 || state === 2 || state === 3) {
  779. if (segment.length > 1 && (char === "*" || char === "+"))
  780. crash(`A repeatable param (${buffer}) must be alone in its segment. eg: '/:ids+.`);
  781. segment.push({
  782. type: 1,
  783. value: buffer,
  784. regexp: customRe,
  785. repeatable: char === "*" || char === "+",
  786. optional: char === "*" || char === "?"
  787. });
  788. } else {
  789. crash("Invalid state to consume buffer");
  790. }
  791. buffer = "";
  792. }
  793. function addCharToBuffer() {
  794. buffer += char;
  795. }
  796. while (i < path.length) {
  797. char = path[i++];
  798. if (char === "\\" && state !== 2) {
  799. previousState = state;
  800. state = 4;
  801. continue;
  802. }
  803. switch (state) {
  804. case 0:
  805. if (char === "/") {
  806. if (buffer) {
  807. consumeBuffer();
  808. }
  809. finalizeSegment();
  810. } else if (char === ":") {
  811. consumeBuffer();
  812. state = 1;
  813. } else {
  814. addCharToBuffer();
  815. }
  816. break;
  817. case 4:
  818. addCharToBuffer();
  819. state = previousState;
  820. break;
  821. case 1:
  822. if (char === "(") {
  823. state = 2;
  824. } else if (VALID_PARAM_RE.test(char)) {
  825. addCharToBuffer();
  826. } else {
  827. consumeBuffer();
  828. state = 0;
  829. if (char !== "*" && char !== "?" && char !== "+")
  830. i--;
  831. }
  832. break;
  833. case 2:
  834. if (char === ")") {
  835. if (customRe[customRe.length - 1] == "\\")
  836. customRe = customRe.slice(0, -1) + char;
  837. else
  838. state = 3;
  839. } else {
  840. customRe += char;
  841. }
  842. break;
  843. case 3:
  844. consumeBuffer();
  845. state = 0;
  846. if (char !== "*" && char !== "?" && char !== "+")
  847. i--;
  848. customRe = "";
  849. break;
  850. default:
  851. crash("Unknown state");
  852. break;
  853. }
  854. }
  855. if (state === 2)
  856. crash(`Unfinished custom RegExp for param "${buffer}"`);
  857. consumeBuffer();
  858. finalizeSegment();
  859. return tokens;
  860. }
  861. function createRouteRecordMatcher(record, parent, options) {
  862. const parser = tokensToParser(tokenizePath(record.path), options);
  863. if (true) {
  864. const existingKeys = /* @__PURE__ */ new Set();
  865. for (const key of parser.keys) {
  866. if (existingKeys.has(key.name))
  867. warn(`Found duplicated params with name "${key.name}" for path "${record.path}". Only the last one will be available on "$route.params".`);
  868. existingKeys.add(key.name);
  869. }
  870. }
  871. const matcher = assign(parser, {
  872. record,
  873. parent,
  874. // these needs to be populated by the parent
  875. children: [],
  876. alias: []
  877. });
  878. if (parent) {
  879. if (!matcher.record.aliasOf === !parent.record.aliasOf)
  880. parent.children.push(matcher);
  881. }
  882. return matcher;
  883. }
  884. function createRouterMatcher(routes, globalOptions) {
  885. const matchers = [];
  886. const matcherMap = /* @__PURE__ */ new Map();
  887. globalOptions = mergeOptions({ strict: false, end: true, sensitive: false }, globalOptions);
  888. function getRecordMatcher(name) {
  889. return matcherMap.get(name);
  890. }
  891. function addRoute(record, parent, originalRecord) {
  892. const isRootAdd = !originalRecord;
  893. const mainNormalizedRecord = normalizeRouteRecord(record);
  894. if (true) {
  895. checkChildMissingNameWithEmptyPath(mainNormalizedRecord, parent);
  896. }
  897. mainNormalizedRecord.aliasOf = originalRecord && originalRecord.record;
  898. const options = mergeOptions(globalOptions, record);
  899. const normalizedRecords = [
  900. mainNormalizedRecord
  901. ];
  902. if ("alias" in record) {
  903. const aliases = typeof record.alias === "string" ? [record.alias] : record.alias;
  904. for (const alias of aliases) {
  905. normalizedRecords.push(assign({}, mainNormalizedRecord, {
  906. // this allows us to hold a copy of the `components` option
  907. // so that async components cache is hold on the original record
  908. components: originalRecord ? originalRecord.record.components : mainNormalizedRecord.components,
  909. path: alias,
  910. // we might be the child of an alias
  911. aliasOf: originalRecord ? originalRecord.record : mainNormalizedRecord
  912. // the aliases are always of the same kind as the original since they
  913. // are defined on the same record
  914. }));
  915. }
  916. }
  917. let matcher;
  918. let originalMatcher;
  919. for (const normalizedRecord of normalizedRecords) {
  920. const { path } = normalizedRecord;
  921. if (parent && path[0] !== "/") {
  922. const parentPath = parent.record.path;
  923. const connectingSlash = parentPath[parentPath.length - 1] === "/" ? "" : "/";
  924. normalizedRecord.path = parent.record.path + (path && connectingSlash + path);
  925. }
  926. if (normalizedRecord.path === "*") {
  927. throw new Error('Catch all routes ("*") must now be defined using a param with a custom regexp.\nSee more at https://next.router.vuejs.org/guide/migration/#removed-star-or-catch-all-routes.');
  928. }
  929. matcher = createRouteRecordMatcher(normalizedRecord, parent, options);
  930. if (parent && path[0] === "/")
  931. checkMissingParamsInAbsolutePath(matcher, parent);
  932. if (originalRecord) {
  933. originalRecord.alias.push(matcher);
  934. if (true) {
  935. checkSameParams(originalRecord, matcher);
  936. }
  937. } else {
  938. originalMatcher = originalMatcher || matcher;
  939. if (originalMatcher !== matcher)
  940. originalMatcher.alias.push(matcher);
  941. if (isRootAdd && record.name && !isAliasRecord(matcher))
  942. removeRoute(record.name);
  943. }
  944. if (mainNormalizedRecord.children) {
  945. const children = mainNormalizedRecord.children;
  946. for (let i = 0; i < children.length; i++) {
  947. addRoute(children[i], matcher, originalRecord && originalRecord.children[i]);
  948. }
  949. }
  950. originalRecord = originalRecord || matcher;
  951. if (matcher.record.components && Object.keys(matcher.record.components).length || matcher.record.name || matcher.record.redirect) {
  952. insertMatcher(matcher);
  953. }
  954. }
  955. return originalMatcher ? () => {
  956. removeRoute(originalMatcher);
  957. } : noop;
  958. }
  959. function removeRoute(matcherRef) {
  960. if (isRouteName(matcherRef)) {
  961. const matcher = matcherMap.get(matcherRef);
  962. if (matcher) {
  963. matcherMap.delete(matcherRef);
  964. matchers.splice(matchers.indexOf(matcher), 1);
  965. matcher.children.forEach(removeRoute);
  966. matcher.alias.forEach(removeRoute);
  967. }
  968. } else {
  969. const index = matchers.indexOf(matcherRef);
  970. if (index > -1) {
  971. matchers.splice(index, 1);
  972. if (matcherRef.record.name)
  973. matcherMap.delete(matcherRef.record.name);
  974. matcherRef.children.forEach(removeRoute);
  975. matcherRef.alias.forEach(removeRoute);
  976. }
  977. }
  978. }
  979. function getRoutes() {
  980. return matchers;
  981. }
  982. function insertMatcher(matcher) {
  983. let i = 0;
  984. while (i < matchers.length && comparePathParserScore(matcher, matchers[i]) >= 0 && // Adding children with empty path should still appear before the parent
  985. // https://github.com/vuejs/router/issues/1124
  986. (matcher.record.path !== matchers[i].record.path || !isRecordChildOf(matcher, matchers[i])))
  987. i++;
  988. matchers.splice(i, 0, matcher);
  989. if (matcher.record.name && !isAliasRecord(matcher))
  990. matcherMap.set(matcher.record.name, matcher);
  991. }
  992. function resolve(location2, currentLocation) {
  993. let matcher;
  994. let params = {};
  995. let path;
  996. let name;
  997. if ("name" in location2 && location2.name) {
  998. matcher = matcherMap.get(location2.name);
  999. if (!matcher)
  1000. throw createRouterError(1, {
  1001. location: location2
  1002. });
  1003. if (true) {
  1004. const invalidParams = Object.keys(location2.params || {}).filter((paramName) => !matcher.keys.find((k) => k.name === paramName));
  1005. if (invalidParams.length) {
  1006. warn(`Discarded invalid param(s) "${invalidParams.join('", "')}" when navigating. See https://github.com/vuejs/router/blob/main/packages/router/CHANGELOG.md#414-2022-08-22 for more details.`);
  1007. }
  1008. }
  1009. name = matcher.record.name;
  1010. params = assign(
  1011. // paramsFromLocation is a new object
  1012. paramsFromLocation(
  1013. currentLocation.params,
  1014. // only keep params that exist in the resolved location
  1015. // TODO: only keep optional params coming from a parent record
  1016. matcher.keys.filter((k) => !k.optional).map((k) => k.name)
  1017. ),
  1018. // discard any existing params in the current location that do not exist here
  1019. // #1497 this ensures better active/exact matching
  1020. location2.params && paramsFromLocation(location2.params, matcher.keys.map((k) => k.name))
  1021. );
  1022. path = matcher.stringify(params);
  1023. } else if ("path" in location2) {
  1024. path = location2.path;
  1025. if (!path.startsWith("/")) {
  1026. warn(`The Matcher cannot resolve relative paths but received "${path}". Unless you directly called \`matcher.resolve("${path}")\`, this is probably a bug in vue-router. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/router.`);
  1027. }
  1028. matcher = matchers.find((m) => m.re.test(path));
  1029. if (matcher) {
  1030. params = matcher.parse(path);
  1031. name = matcher.record.name;
  1032. }
  1033. } else {
  1034. matcher = currentLocation.name ? matcherMap.get(currentLocation.name) : matchers.find((m) => m.re.test(currentLocation.path));
  1035. if (!matcher)
  1036. throw createRouterError(1, {
  1037. location: location2,
  1038. currentLocation
  1039. });
  1040. name = matcher.record.name;
  1041. params = assign({}, currentLocation.params, location2.params);
  1042. path = matcher.stringify(params);
  1043. }
  1044. const matched = [];
  1045. let parentMatcher = matcher;
  1046. while (parentMatcher) {
  1047. matched.unshift(parentMatcher.record);
  1048. parentMatcher = parentMatcher.parent;
  1049. }
  1050. return {
  1051. name,
  1052. path,
  1053. params,
  1054. matched,
  1055. meta: mergeMetaFields(matched)
  1056. };
  1057. }
  1058. routes.forEach((route) => addRoute(route));
  1059. return { addRoute, resolve, removeRoute, getRoutes, getRecordMatcher };
  1060. }
  1061. function paramsFromLocation(params, keys) {
  1062. const newParams = {};
  1063. for (const key of keys) {
  1064. if (key in params)
  1065. newParams[key] = params[key];
  1066. }
  1067. return newParams;
  1068. }
  1069. function normalizeRouteRecord(record) {
  1070. return {
  1071. path: record.path,
  1072. redirect: record.redirect,
  1073. name: record.name,
  1074. meta: record.meta || {},
  1075. aliasOf: void 0,
  1076. beforeEnter: record.beforeEnter,
  1077. props: normalizeRecordProps(record),
  1078. children: record.children || [],
  1079. instances: {},
  1080. leaveGuards: /* @__PURE__ */ new Set(),
  1081. updateGuards: /* @__PURE__ */ new Set(),
  1082. enterCallbacks: {},
  1083. components: "components" in record ? record.components || null : record.component && { default: record.component }
  1084. };
  1085. }
  1086. function normalizeRecordProps(record) {
  1087. const propsObject = {};
  1088. const props = record.props || false;
  1089. if ("component" in record) {
  1090. propsObject.default = props;
  1091. } else {
  1092. for (const name in record.components)
  1093. propsObject[name] = typeof props === "boolean" ? props : props[name];
  1094. }
  1095. return propsObject;
  1096. }
  1097. function isAliasRecord(record) {
  1098. while (record) {
  1099. if (record.record.aliasOf)
  1100. return true;
  1101. record = record.parent;
  1102. }
  1103. return false;
  1104. }
  1105. function mergeMetaFields(matched) {
  1106. return matched.reduce((meta, record) => assign(meta, record.meta), {});
  1107. }
  1108. function mergeOptions(defaults, partialOptions) {
  1109. const options = {};
  1110. for (const key in defaults) {
  1111. options[key] = key in partialOptions ? partialOptions[key] : defaults[key];
  1112. }
  1113. return options;
  1114. }
  1115. function isSameParam(a, b) {
  1116. return a.name === b.name && a.optional === b.optional && a.repeatable === b.repeatable;
  1117. }
  1118. function checkSameParams(a, b) {
  1119. for (const key of a.keys) {
  1120. if (!key.optional && !b.keys.find(isSameParam.bind(null, key)))
  1121. return warn(`Alias "${b.record.path}" and the original record: "${a.record.path}" must have the exact same param named "${key.name}"`);
  1122. }
  1123. for (const key of b.keys) {
  1124. if (!key.optional && !a.keys.find(isSameParam.bind(null, key)))
  1125. return warn(`Alias "${b.record.path}" and the original record: "${a.record.path}" must have the exact same param named "${key.name}"`);
  1126. }
  1127. }
  1128. function checkChildMissingNameWithEmptyPath(mainNormalizedRecord, parent) {
  1129. if (parent && parent.record.name && !mainNormalizedRecord.name && !mainNormalizedRecord.path) {
  1130. warn(`The route named "${String(parent.record.name)}" has a child without a name and an empty path. Using that name won't render the empty path child so you probably want to move the name to the child instead. If this is intentional, add a name to the child route to remove the warning.`);
  1131. }
  1132. }
  1133. function checkMissingParamsInAbsolutePath(record, parent) {
  1134. for (const key of parent.keys) {
  1135. if (!record.keys.find(isSameParam.bind(null, key)))
  1136. return warn(`Absolute path "${record.record.path}" must have the exact same param named "${key.name}" as its parent "${parent.record.path}".`);
  1137. }
  1138. }
  1139. function isRecordChildOf(record, parent) {
  1140. return parent.children.some((child) => child === record || isRecordChildOf(record, child));
  1141. }
  1142. var HASH_RE = /#/g;
  1143. var AMPERSAND_RE = /&/g;
  1144. var SLASH_RE = /\//g;
  1145. var EQUAL_RE = /=/g;
  1146. var IM_RE = /\?/g;
  1147. var PLUS_RE = /\+/g;
  1148. var ENC_BRACKET_OPEN_RE = /%5B/g;
  1149. var ENC_BRACKET_CLOSE_RE = /%5D/g;
  1150. var ENC_CARET_RE = /%5E/g;
  1151. var ENC_BACKTICK_RE = /%60/g;
  1152. var ENC_CURLY_OPEN_RE = /%7B/g;
  1153. var ENC_PIPE_RE = /%7C/g;
  1154. var ENC_CURLY_CLOSE_RE = /%7D/g;
  1155. var ENC_SPACE_RE = /%20/g;
  1156. function commonEncode(text) {
  1157. return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
  1158. }
  1159. function encodeHash(text) {
  1160. return commonEncode(text).replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
  1161. }
  1162. function encodeQueryValue(text) {
  1163. return commonEncode(text).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
  1164. }
  1165. function encodeQueryKey(text) {
  1166. return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
  1167. }
  1168. function encodePath(text) {
  1169. return commonEncode(text).replace(HASH_RE, "%23").replace(IM_RE, "%3F");
  1170. }
  1171. function encodeParam(text) {
  1172. return text == null ? "" : encodePath(text).replace(SLASH_RE, "%2F");
  1173. }
  1174. function decode(text) {
  1175. try {
  1176. return decodeURIComponent("" + text);
  1177. } catch (err) {
  1178. warn(`Error decoding "${text}". Using original value`);
  1179. }
  1180. return "" + text;
  1181. }
  1182. function parseQuery(search) {
  1183. const query = {};
  1184. if (search === "" || search === "?")
  1185. return query;
  1186. const hasLeadingIM = search[0] === "?";
  1187. const searchParams = (hasLeadingIM ? search.slice(1) : search).split("&");
  1188. for (let i = 0; i < searchParams.length; ++i) {
  1189. const searchParam = searchParams[i].replace(PLUS_RE, " ");
  1190. const eqPos = searchParam.indexOf("=");
  1191. const key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos));
  1192. const value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1));
  1193. if (key in query) {
  1194. let currentValue = query[key];
  1195. if (!isArray(currentValue)) {
  1196. currentValue = query[key] = [currentValue];
  1197. }
  1198. currentValue.push(value);
  1199. } else {
  1200. query[key] = value;
  1201. }
  1202. }
  1203. return query;
  1204. }
  1205. function stringifyQuery(query) {
  1206. let search = "";
  1207. for (let key in query) {
  1208. const value = query[key];
  1209. key = encodeQueryKey(key);
  1210. if (value == null) {
  1211. if (value !== void 0) {
  1212. search += (search.length ? "&" : "") + key;
  1213. }
  1214. continue;
  1215. }
  1216. const values = isArray(value) ? value.map((v) => v && encodeQueryValue(v)) : [value && encodeQueryValue(value)];
  1217. values.forEach((value2) => {
  1218. if (value2 !== void 0) {
  1219. search += (search.length ? "&" : "") + key;
  1220. if (value2 != null)
  1221. search += "=" + value2;
  1222. }
  1223. });
  1224. }
  1225. return search;
  1226. }
  1227. function normalizeQuery(query) {
  1228. const normalizedQuery = {};
  1229. for (const key in query) {
  1230. const value = query[key];
  1231. if (value !== void 0) {
  1232. normalizedQuery[key] = isArray(value) ? value.map((v) => v == null ? null : "" + v) : value == null ? value : "" + value;
  1233. }
  1234. }
  1235. return normalizedQuery;
  1236. }
  1237. var matchedRouteKey = Symbol(true ? "router view location matched" : "");
  1238. var viewDepthKey = Symbol(true ? "router view depth" : "");
  1239. var routerKey = Symbol(true ? "router" : "");
  1240. var routeLocationKey = Symbol(true ? "route location" : "");
  1241. var routerViewLocationKey = Symbol(true ? "router view location" : "");
  1242. function useCallbacks() {
  1243. let handlers = [];
  1244. function add(handler) {
  1245. handlers.push(handler);
  1246. return () => {
  1247. const i = handlers.indexOf(handler);
  1248. if (i > -1)
  1249. handlers.splice(i, 1);
  1250. };
  1251. }
  1252. function reset() {
  1253. handlers = [];
  1254. }
  1255. return {
  1256. add,
  1257. list: () => handlers,
  1258. reset
  1259. };
  1260. }
  1261. function registerGuard(record, name, guard) {
  1262. const removeFromList = () => {
  1263. record[name].delete(guard);
  1264. };
  1265. onUnmounted(removeFromList);
  1266. onDeactivated(removeFromList);
  1267. onActivated(() => {
  1268. record[name].add(guard);
  1269. });
  1270. record[name].add(guard);
  1271. }
  1272. function onBeforeRouteLeave(leaveGuard) {
  1273. if (!getCurrentInstance()) {
  1274. warn("getCurrentInstance() returned null. onBeforeRouteLeave() must be called at the top of a setup function");
  1275. return;
  1276. }
  1277. const activeRecord = inject(
  1278. matchedRouteKey,
  1279. // to avoid warning
  1280. {}
  1281. ).value;
  1282. if (!activeRecord) {
  1283. warn("No active route record was found when calling `onBeforeRouteLeave()`. Make sure you call this function inside a component child of <router-view>. Maybe you called it inside of App.vue?");
  1284. return;
  1285. }
  1286. registerGuard(activeRecord, "leaveGuards", leaveGuard);
  1287. }
  1288. function onBeforeRouteUpdate(updateGuard) {
  1289. if (!getCurrentInstance()) {
  1290. warn("getCurrentInstance() returned null. onBeforeRouteUpdate() must be called at the top of a setup function");
  1291. return;
  1292. }
  1293. const activeRecord = inject(
  1294. matchedRouteKey,
  1295. // to avoid warning
  1296. {}
  1297. ).value;
  1298. if (!activeRecord) {
  1299. warn("No active route record was found when calling `onBeforeRouteUpdate()`. Make sure you call this function inside a component child of <router-view>. Maybe you called it inside of App.vue?");
  1300. return;
  1301. }
  1302. registerGuard(activeRecord, "updateGuards", updateGuard);
  1303. }
  1304. function guardToPromiseFn(guard, to, from, record, name) {
  1305. const enterCallbackArray = record && // name is defined if record is because of the function overload
  1306. (record.enterCallbacks[name] = record.enterCallbacks[name] || []);
  1307. return () => new Promise((resolve, reject) => {
  1308. const next = (valid) => {
  1309. if (valid === false) {
  1310. reject(createRouterError(4, {
  1311. from,
  1312. to
  1313. }));
  1314. } else if (valid instanceof Error) {
  1315. reject(valid);
  1316. } else if (isRouteLocation(valid)) {
  1317. reject(createRouterError(2, {
  1318. from: to,
  1319. to: valid
  1320. }));
  1321. } else {
  1322. if (enterCallbackArray && // since enterCallbackArray is truthy, both record and name also are
  1323. record.enterCallbacks[name] === enterCallbackArray && typeof valid === "function") {
  1324. enterCallbackArray.push(valid);
  1325. }
  1326. resolve();
  1327. }
  1328. };
  1329. const guardReturn = guard.call(record && record.instances[name], to, from, true ? canOnlyBeCalledOnce(next, to, from) : next);
  1330. let guardCall = Promise.resolve(guardReturn);
  1331. if (guard.length < 3)
  1332. guardCall = guardCall.then(next);
  1333. if (guard.length > 2) {
  1334. const message = `The "next" callback was never called inside of ${guard.name ? '"' + guard.name + '"' : ""}:
  1335. ${guard.toString()}
  1336. . If you are returning a value instead of calling "next", make sure to remove the "next" parameter from your function.`;
  1337. if (typeof guardReturn === "object" && "then" in guardReturn) {
  1338. guardCall = guardCall.then((resolvedValue) => {
  1339. if (!next._called) {
  1340. warn(message);
  1341. return Promise.reject(new Error("Invalid navigation guard"));
  1342. }
  1343. return resolvedValue;
  1344. });
  1345. } else if (guardReturn !== void 0) {
  1346. if (!next._called) {
  1347. warn(message);
  1348. reject(new Error("Invalid navigation guard"));
  1349. return;
  1350. }
  1351. }
  1352. }
  1353. guardCall.catch((err) => reject(err));
  1354. });
  1355. }
  1356. function canOnlyBeCalledOnce(next, to, from) {
  1357. let called = 0;
  1358. return function() {
  1359. if (called++ === 1)
  1360. warn(`The "next" callback was called more than once in one navigation guard when going from "${from.fullPath}" to "${to.fullPath}". It should be called exactly one time in each navigation guard. This will fail in production.`);
  1361. next._called = true;
  1362. if (called === 1)
  1363. next.apply(null, arguments);
  1364. };
  1365. }
  1366. function extractComponentsGuards(matched, guardType, to, from) {
  1367. const guards = [];
  1368. for (const record of matched) {
  1369. if (!record.components && !record.children.length) {
  1370. warn(`Record with path "${record.path}" is either missing a "component(s)" or "children" property.`);
  1371. }
  1372. for (const name in record.components) {
  1373. let rawComponent = record.components[name];
  1374. if (true) {
  1375. if (!rawComponent || typeof rawComponent !== "object" && typeof rawComponent !== "function") {
  1376. warn(`Component "${name}" in record with path "${record.path}" is not a valid component. Received "${String(rawComponent)}".`);
  1377. throw new Error("Invalid route component");
  1378. } else if ("then" in rawComponent) {
  1379. warn(`Component "${name}" in record with path "${record.path}" is a Promise instead of a function that returns a Promise. Did you write "import('./MyPage.vue')" instead of "() => import('./MyPage.vue')" ? This will break in production if not fixed.`);
  1380. const promise = rawComponent;
  1381. rawComponent = () => promise;
  1382. } else if (rawComponent.__asyncLoader && // warn only once per component
  1383. !rawComponent.__warnedDefineAsync) {
  1384. rawComponent.__warnedDefineAsync = true;
  1385. warn(`Component "${name}" in record with path "${record.path}" is defined using "defineAsyncComponent()". Write "() => import('./MyPage.vue')" instead of "defineAsyncComponent(() => import('./MyPage.vue'))".`);
  1386. }
  1387. }
  1388. if (guardType !== "beforeRouteEnter" && !record.instances[name])
  1389. continue;
  1390. if (isRouteComponent(rawComponent)) {
  1391. const options = rawComponent.__vccOpts || rawComponent;
  1392. const guard = options[guardType];
  1393. guard && guards.push(guardToPromiseFn(guard, to, from, record, name));
  1394. } else {
  1395. let componentPromise = rawComponent();
  1396. if (!("catch" in componentPromise)) {
  1397. warn(`Component "${name}" in record with path "${record.path}" is a function that does not return a Promise. If you were passing a functional component, make sure to add a "displayName" to the component. This will break in production if not fixed.`);
  1398. componentPromise = Promise.resolve(componentPromise);
  1399. }
  1400. guards.push(() => componentPromise.then((resolved) => {
  1401. if (!resolved)
  1402. return Promise.reject(new Error(`Couldn't resolve component "${name}" at "${record.path}"`));
  1403. const resolvedComponent = isESModule(resolved) ? resolved.default : resolved;
  1404. record.components[name] = resolvedComponent;
  1405. const options = resolvedComponent.__vccOpts || resolvedComponent;
  1406. const guard = options[guardType];
  1407. return guard && guardToPromiseFn(guard, to, from, record, name)();
  1408. }));
  1409. }
  1410. }
  1411. }
  1412. return guards;
  1413. }
  1414. function isRouteComponent(component) {
  1415. return typeof component === "object" || "displayName" in component || "props" in component || "__vccOpts" in component;
  1416. }
  1417. function loadRouteLocation(route) {
  1418. return route.matched.every((record) => record.redirect) ? Promise.reject(new Error("Cannot load a route that redirects.")) : Promise.all(route.matched.map((record) => record.components && Promise.all(Object.keys(record.components).reduce((promises, name) => {
  1419. const rawComponent = record.components[name];
  1420. if (typeof rawComponent === "function" && !("displayName" in rawComponent)) {
  1421. promises.push(rawComponent().then((resolved) => {
  1422. if (!resolved)
  1423. return Promise.reject(new Error(`Couldn't resolve component "${name}" at "${record.path}". Ensure you passed a function that returns a promise.`));
  1424. const resolvedComponent = isESModule(resolved) ? resolved.default : resolved;
  1425. record.components[name] = resolvedComponent;
  1426. return;
  1427. }));
  1428. }
  1429. return promises;
  1430. }, [])))).then(() => route);
  1431. }
  1432. function useLink(props) {
  1433. const router = inject(routerKey);
  1434. const currentRoute = inject(routeLocationKey);
  1435. const route = computed(() => router.resolve(unref(props.to)));
  1436. const activeRecordIndex = computed(() => {
  1437. const { matched } = route.value;
  1438. const { length } = matched;
  1439. const routeMatched = matched[length - 1];
  1440. const currentMatched = currentRoute.matched;
  1441. if (!routeMatched || !currentMatched.length)
  1442. return -1;
  1443. const index = currentMatched.findIndex(isSameRouteRecord.bind(null, routeMatched));
  1444. if (index > -1)
  1445. return index;
  1446. const parentRecordPath = getOriginalPath(matched[length - 2]);
  1447. return (
  1448. // we are dealing with nested routes
  1449. length > 1 && // if the parent and matched route have the same path, this link is
  1450. // referring to the empty child. Or we currently are on a different
  1451. // child of the same parent
  1452. getOriginalPath(routeMatched) === parentRecordPath && // avoid comparing the child with its parent
  1453. currentMatched[currentMatched.length - 1].path !== parentRecordPath ? currentMatched.findIndex(isSameRouteRecord.bind(null, matched[length - 2])) : index
  1454. );
  1455. });
  1456. const isActive = computed(() => activeRecordIndex.value > -1 && includesParams(currentRoute.params, route.value.params));
  1457. const isExactActive = computed(() => activeRecordIndex.value > -1 && activeRecordIndex.value === currentRoute.matched.length - 1 && isSameRouteLocationParams(currentRoute.params, route.value.params));
  1458. function navigate(e = {}) {
  1459. if (guardEvent(e)) {
  1460. return router[unref(props.replace) ? "replace" : "push"](
  1461. unref(props.to)
  1462. // avoid uncaught errors are they are logged anyway
  1463. ).catch(noop);
  1464. }
  1465. return Promise.resolve();
  1466. }
  1467. if (isBrowser) {
  1468. const instance = getCurrentInstance();
  1469. if (instance) {
  1470. const linkContextDevtools = {
  1471. route: route.value,
  1472. isActive: isActive.value,
  1473. isExactActive: isExactActive.value
  1474. };
  1475. instance.__vrl_devtools = instance.__vrl_devtools || [];
  1476. instance.__vrl_devtools.push(linkContextDevtools);
  1477. watchEffect(() => {
  1478. linkContextDevtools.route = route.value;
  1479. linkContextDevtools.isActive = isActive.value;
  1480. linkContextDevtools.isExactActive = isExactActive.value;
  1481. }, { flush: "post" });
  1482. }
  1483. }
  1484. return {
  1485. route,
  1486. href: computed(() => route.value.href),
  1487. isActive,
  1488. isExactActive,
  1489. navigate
  1490. };
  1491. }
  1492. var RouterLinkImpl = defineComponent({
  1493. name: "RouterLink",
  1494. compatConfig: { MODE: 3 },
  1495. props: {
  1496. to: {
  1497. type: [String, Object],
  1498. required: true
  1499. },
  1500. replace: Boolean,
  1501. activeClass: String,
  1502. // inactiveClass: String,
  1503. exactActiveClass: String,
  1504. custom: Boolean,
  1505. ariaCurrentValue: {
  1506. type: String,
  1507. default: "page"
  1508. }
  1509. },
  1510. useLink,
  1511. setup(props, { slots }) {
  1512. const link = reactive(useLink(props));
  1513. const { options } = inject(routerKey);
  1514. const elClass = computed(() => ({
  1515. [getLinkClass(props.activeClass, options.linkActiveClass, "router-link-active")]: link.isActive,
  1516. // [getLinkClass(
  1517. // props.inactiveClass,
  1518. // options.linkInactiveClass,
  1519. // 'router-link-inactive'
  1520. // )]: !link.isExactActive,
  1521. [getLinkClass(props.exactActiveClass, options.linkExactActiveClass, "router-link-exact-active")]: link.isExactActive
  1522. }));
  1523. return () => {
  1524. const children = slots.default && slots.default(link);
  1525. return props.custom ? children : h("a", {
  1526. "aria-current": link.isExactActive ? props.ariaCurrentValue : null,
  1527. href: link.href,
  1528. // this would override user added attrs but Vue will still add
  1529. // the listener, so we end up triggering both
  1530. onClick: link.navigate,
  1531. class: elClass.value
  1532. }, children);
  1533. };
  1534. }
  1535. });
  1536. var RouterLink = RouterLinkImpl;
  1537. function guardEvent(e) {
  1538. if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)
  1539. return;
  1540. if (e.defaultPrevented)
  1541. return;
  1542. if (e.button !== void 0 && e.button !== 0)
  1543. return;
  1544. if (e.currentTarget && e.currentTarget.getAttribute) {
  1545. const target = e.currentTarget.getAttribute("target");
  1546. if (/\b_blank\b/i.test(target))
  1547. return;
  1548. }
  1549. if (e.preventDefault)
  1550. e.preventDefault();
  1551. return true;
  1552. }
  1553. function includesParams(outer, inner) {
  1554. for (const key in inner) {
  1555. const innerValue = inner[key];
  1556. const outerValue = outer[key];
  1557. if (typeof innerValue === "string") {
  1558. if (innerValue !== outerValue)
  1559. return false;
  1560. } else {
  1561. if (!isArray(outerValue) || outerValue.length !== innerValue.length || innerValue.some((value, i) => value !== outerValue[i]))
  1562. return false;
  1563. }
  1564. }
  1565. return true;
  1566. }
  1567. function getOriginalPath(record) {
  1568. return record ? record.aliasOf ? record.aliasOf.path : record.path : "";
  1569. }
  1570. var getLinkClass = (propClass, globalClass, defaultClass) => propClass != null ? propClass : globalClass != null ? globalClass : defaultClass;
  1571. var RouterViewImpl = defineComponent({
  1572. name: "RouterView",
  1573. // #674 we manually inherit them
  1574. inheritAttrs: false,
  1575. props: {
  1576. name: {
  1577. type: String,
  1578. default: "default"
  1579. },
  1580. route: Object
  1581. },
  1582. // Better compat for @vue/compat users
  1583. // https://github.com/vuejs/router/issues/1315
  1584. compatConfig: { MODE: 3 },
  1585. setup(props, { attrs, slots }) {
  1586. warnDeprecatedUsage();
  1587. const injectedRoute = inject(routerViewLocationKey);
  1588. const routeToDisplay = computed(() => props.route || injectedRoute.value);
  1589. const injectedDepth = inject(viewDepthKey, 0);
  1590. const depth = computed(() => {
  1591. let initialDepth = unref(injectedDepth);
  1592. const { matched } = routeToDisplay.value;
  1593. let matchedRoute;
  1594. while ((matchedRoute = matched[initialDepth]) && !matchedRoute.components) {
  1595. initialDepth++;
  1596. }
  1597. return initialDepth;
  1598. });
  1599. const matchedRouteRef = computed(() => routeToDisplay.value.matched[depth.value]);
  1600. provide(viewDepthKey, computed(() => depth.value + 1));
  1601. provide(matchedRouteKey, matchedRouteRef);
  1602. provide(routerViewLocationKey, routeToDisplay);
  1603. const viewRef = ref();
  1604. watch(() => [viewRef.value, matchedRouteRef.value, props.name], ([instance, to, name], [oldInstance, from, oldName]) => {
  1605. if (to) {
  1606. to.instances[name] = instance;
  1607. if (from && from !== to && instance && instance === oldInstance) {
  1608. if (!to.leaveGuards.size) {
  1609. to.leaveGuards = from.leaveGuards;
  1610. }
  1611. if (!to.updateGuards.size) {
  1612. to.updateGuards = from.updateGuards;
  1613. }
  1614. }
  1615. }
  1616. if (instance && to && // if there is no instance but to and from are the same this might be
  1617. // the first visit
  1618. (!from || !isSameRouteRecord(to, from) || !oldInstance)) {
  1619. (to.enterCallbacks[name] || []).forEach((callback) => callback(instance));
  1620. }
  1621. }, { flush: "post" });
  1622. return () => {
  1623. const route = routeToDisplay.value;
  1624. const currentName = props.name;
  1625. const matchedRoute = matchedRouteRef.value;
  1626. const ViewComponent = matchedRoute && matchedRoute.components[currentName];
  1627. if (!ViewComponent) {
  1628. return normalizeSlot(slots.default, { Component: ViewComponent, route });
  1629. }
  1630. const routePropsOption = matchedRoute.props[currentName];
  1631. const routeProps = routePropsOption ? routePropsOption === true ? route.params : typeof routePropsOption === "function" ? routePropsOption(route) : routePropsOption : null;
  1632. const onVnodeUnmounted = (vnode) => {
  1633. if (vnode.component.isUnmounted) {
  1634. matchedRoute.instances[currentName] = null;
  1635. }
  1636. };
  1637. const component = h(ViewComponent, assign({}, routeProps, attrs, {
  1638. onVnodeUnmounted,
  1639. ref: viewRef
  1640. }));
  1641. if (isBrowser && component.ref) {
  1642. const info = {
  1643. depth: depth.value,
  1644. name: matchedRoute.name,
  1645. path: matchedRoute.path,
  1646. meta: matchedRoute.meta
  1647. };
  1648. const internalInstances = isArray(component.ref) ? component.ref.map((r) => r.i) : [component.ref.i];
  1649. internalInstances.forEach((instance) => {
  1650. instance.__vrv_devtools = info;
  1651. });
  1652. }
  1653. return (
  1654. // pass the vnode to the slot as a prop.
  1655. // h and <component :is="..."> both accept vnodes
  1656. normalizeSlot(slots.default, { Component: component, route }) || component
  1657. );
  1658. };
  1659. }
  1660. });
  1661. function normalizeSlot(slot, data) {
  1662. if (!slot)
  1663. return null;
  1664. const slotContent = slot(data);
  1665. return slotContent.length === 1 ? slotContent[0] : slotContent;
  1666. }
  1667. var RouterView = RouterViewImpl;
  1668. function warnDeprecatedUsage() {
  1669. const instance = getCurrentInstance();
  1670. const parentName = instance.parent && instance.parent.type.name;
  1671. if (parentName && (parentName === "KeepAlive" || parentName.includes("Transition"))) {
  1672. const comp = parentName === "KeepAlive" ? "keep-alive" : "transition";
  1673. warn(`<router-view> can no longer be used directly inside <transition> or <keep-alive>.
  1674. Use slot props instead:
  1675. <router-view v-slot="{ Component }">
  1676. <${comp}>
  1677. <component :is="Component" />
  1678. </${comp}>
  1679. </router-view>`);
  1680. }
  1681. }
  1682. function formatRouteLocation(routeLocation, tooltip) {
  1683. const copy = assign({}, routeLocation, {
  1684. // remove variables that can contain vue instances
  1685. matched: routeLocation.matched.map((matched) => omit(matched, ["instances", "children", "aliasOf"]))
  1686. });
  1687. return {
  1688. _custom: {
  1689. type: null,
  1690. readOnly: true,
  1691. display: routeLocation.fullPath,
  1692. tooltip,
  1693. value: copy
  1694. }
  1695. };
  1696. }
  1697. function formatDisplay(display) {
  1698. return {
  1699. _custom: {
  1700. display
  1701. }
  1702. };
  1703. }
  1704. var routerId = 0;
  1705. function addDevtools(app, router, matcher) {
  1706. if (router.__hasDevtools)
  1707. return;
  1708. router.__hasDevtools = true;
  1709. const id = routerId++;
  1710. setupDevtoolsPlugin({
  1711. id: "org.vuejs.router" + (id ? "." + id : ""),
  1712. label: "Vue Router",
  1713. packageName: "vue-router",
  1714. homepage: "https://router.vuejs.org",
  1715. logo: "https://router.vuejs.org/logo.png",
  1716. componentStateTypes: ["Routing"],
  1717. app
  1718. }, (api) => {
  1719. if (typeof api.now !== "function") {
  1720. console.warn("[Vue Router]: You seem to be using an outdated version of Vue Devtools. Are you still using the Beta release instead of the stable one? You can find the links at https://devtools.vuejs.org/guide/installation.html.");
  1721. }
  1722. api.on.inspectComponent((payload, ctx) => {
  1723. if (payload.instanceData) {
  1724. payload.instanceData.state.push({
  1725. type: "Routing",
  1726. key: "$route",
  1727. editable: false,
  1728. value: formatRouteLocation(router.currentRoute.value, "Current Route")
  1729. });
  1730. }
  1731. });
  1732. api.on.visitComponentTree(({ treeNode: node, componentInstance }) => {
  1733. if (componentInstance.__vrv_devtools) {
  1734. const info = componentInstance.__vrv_devtools;
  1735. node.tags.push({
  1736. label: (info.name ? `${info.name.toString()}: ` : "") + info.path,
  1737. textColor: 0,
  1738. tooltip: "This component is rendered by &lt;router-view&gt;",
  1739. backgroundColor: PINK_500
  1740. });
  1741. }
  1742. if (isArray(componentInstance.__vrl_devtools)) {
  1743. componentInstance.__devtoolsApi = api;
  1744. componentInstance.__vrl_devtools.forEach((devtoolsData) => {
  1745. let backgroundColor = ORANGE_400;
  1746. let tooltip = "";
  1747. if (devtoolsData.isExactActive) {
  1748. backgroundColor = LIME_500;
  1749. tooltip = "This is exactly active";
  1750. } else if (devtoolsData.isActive) {
  1751. backgroundColor = BLUE_600;
  1752. tooltip = "This link is active";
  1753. }
  1754. node.tags.push({
  1755. label: devtoolsData.route.path,
  1756. textColor: 0,
  1757. tooltip,
  1758. backgroundColor
  1759. });
  1760. });
  1761. }
  1762. });
  1763. watch(router.currentRoute, () => {
  1764. refreshRoutesView();
  1765. api.notifyComponentUpdate();
  1766. api.sendInspectorTree(routerInspectorId);
  1767. api.sendInspectorState(routerInspectorId);
  1768. });
  1769. const navigationsLayerId = "router:navigations:" + id;
  1770. api.addTimelineLayer({
  1771. id: navigationsLayerId,
  1772. label: `Router${id ? " " + id : ""} Navigations`,
  1773. color: 4237508
  1774. });
  1775. router.onError((error, to) => {
  1776. api.addTimelineEvent({
  1777. layerId: navigationsLayerId,
  1778. event: {
  1779. title: "Error during Navigation",
  1780. subtitle: to.fullPath,
  1781. logType: "error",
  1782. time: api.now(),
  1783. data: { error },
  1784. groupId: to.meta.__navigationId
  1785. }
  1786. });
  1787. });
  1788. let navigationId = 0;
  1789. router.beforeEach((to, from) => {
  1790. const data = {
  1791. guard: formatDisplay("beforeEach"),
  1792. from: formatRouteLocation(from, "Current Location during this navigation"),
  1793. to: formatRouteLocation(to, "Target location")
  1794. };
  1795. Object.defineProperty(to.meta, "__navigationId", {
  1796. value: navigationId++
  1797. });
  1798. api.addTimelineEvent({
  1799. layerId: navigationsLayerId,
  1800. event: {
  1801. time: api.now(),
  1802. title: "Start of navigation",
  1803. subtitle: to.fullPath,
  1804. data,
  1805. groupId: to.meta.__navigationId
  1806. }
  1807. });
  1808. });
  1809. router.afterEach((to, from, failure) => {
  1810. const data = {
  1811. guard: formatDisplay("afterEach")
  1812. };
  1813. if (failure) {
  1814. data.failure = {
  1815. _custom: {
  1816. type: Error,
  1817. readOnly: true,
  1818. display: failure ? failure.message : "",
  1819. tooltip: "Navigation Failure",
  1820. value: failure
  1821. }
  1822. };
  1823. data.status = formatDisplay("❌");
  1824. } else {
  1825. data.status = formatDisplay("✅");
  1826. }
  1827. data.from = formatRouteLocation(from, "Current Location during this navigation");
  1828. data.to = formatRouteLocation(to, "Target location");
  1829. api.addTimelineEvent({
  1830. layerId: navigationsLayerId,
  1831. event: {
  1832. title: "End of navigation",
  1833. subtitle: to.fullPath,
  1834. time: api.now(),
  1835. data,
  1836. logType: failure ? "warning" : "default",
  1837. groupId: to.meta.__navigationId
  1838. }
  1839. });
  1840. });
  1841. const routerInspectorId = "router-inspector:" + id;
  1842. api.addInspector({
  1843. id: routerInspectorId,
  1844. label: "Routes" + (id ? " " + id : ""),
  1845. icon: "book",
  1846. treeFilterPlaceholder: "Search routes"
  1847. });
  1848. function refreshRoutesView() {
  1849. if (!activeRoutesPayload)
  1850. return;
  1851. const payload = activeRoutesPayload;
  1852. let routes = matcher.getRoutes().filter((route) => !route.parent);
  1853. routes.forEach(resetMatchStateOnRouteRecord);
  1854. if (payload.filter) {
  1855. routes = routes.filter((route) => (
  1856. // save matches state based on the payload
  1857. isRouteMatching(route, payload.filter.toLowerCase())
  1858. ));
  1859. }
  1860. routes.forEach((route) => markRouteRecordActive(route, router.currentRoute.value));
  1861. payload.rootNodes = routes.map(formatRouteRecordForInspector);
  1862. }
  1863. let activeRoutesPayload;
  1864. api.on.getInspectorTree((payload) => {
  1865. activeRoutesPayload = payload;
  1866. if (payload.app === app && payload.inspectorId === routerInspectorId) {
  1867. refreshRoutesView();
  1868. }
  1869. });
  1870. api.on.getInspectorState((payload) => {
  1871. if (payload.app === app && payload.inspectorId === routerInspectorId) {
  1872. const routes = matcher.getRoutes();
  1873. const route = routes.find((route2) => route2.record.__vd_id === payload.nodeId);
  1874. if (route) {
  1875. payload.state = {
  1876. options: formatRouteRecordMatcherForStateInspector(route)
  1877. };
  1878. }
  1879. }
  1880. });
  1881. api.sendInspectorTree(routerInspectorId);
  1882. api.sendInspectorState(routerInspectorId);
  1883. });
  1884. }
  1885. function modifierForKey(key) {
  1886. if (key.optional) {
  1887. return key.repeatable ? "*" : "?";
  1888. } else {
  1889. return key.repeatable ? "+" : "";
  1890. }
  1891. }
  1892. function formatRouteRecordMatcherForStateInspector(route) {
  1893. const { record } = route;
  1894. const fields = [
  1895. { editable: false, key: "path", value: record.path }
  1896. ];
  1897. if (record.name != null) {
  1898. fields.push({
  1899. editable: false,
  1900. key: "name",
  1901. value: record.name
  1902. });
  1903. }
  1904. fields.push({ editable: false, key: "regexp", value: route.re });
  1905. if (route.keys.length) {
  1906. fields.push({
  1907. editable: false,
  1908. key: "keys",
  1909. value: {
  1910. _custom: {
  1911. type: null,
  1912. readOnly: true,
  1913. display: route.keys.map((key) => `${key.name}${modifierForKey(key)}`).join(" "),
  1914. tooltip: "Param keys",
  1915. value: route.keys
  1916. }
  1917. }
  1918. });
  1919. }
  1920. if (record.redirect != null) {
  1921. fields.push({
  1922. editable: false,
  1923. key: "redirect",
  1924. value: record.redirect
  1925. });
  1926. }
  1927. if (route.alias.length) {
  1928. fields.push({
  1929. editable: false,
  1930. key: "aliases",
  1931. value: route.alias.map((alias) => alias.record.path)
  1932. });
  1933. }
  1934. if (Object.keys(route.record.meta).length) {
  1935. fields.push({
  1936. editable: false,
  1937. key: "meta",
  1938. value: route.record.meta
  1939. });
  1940. }
  1941. fields.push({
  1942. key: "score",
  1943. editable: false,
  1944. value: {
  1945. _custom: {
  1946. type: null,
  1947. readOnly: true,
  1948. display: route.score.map((score) => score.join(", ")).join(" | "),
  1949. tooltip: "Score used to sort routes",
  1950. value: route.score
  1951. }
  1952. }
  1953. });
  1954. return fields;
  1955. }
  1956. var PINK_500 = 15485081;
  1957. var BLUE_600 = 2450411;
  1958. var LIME_500 = 8702998;
  1959. var CYAN_400 = 2282478;
  1960. var ORANGE_400 = 16486972;
  1961. var DARK = 6710886;
  1962. function formatRouteRecordForInspector(route) {
  1963. const tags = [];
  1964. const { record } = route;
  1965. if (record.name != null) {
  1966. tags.push({
  1967. label: String(record.name),
  1968. textColor: 0,
  1969. backgroundColor: CYAN_400
  1970. });
  1971. }
  1972. if (record.aliasOf) {
  1973. tags.push({
  1974. label: "alias",
  1975. textColor: 0,
  1976. backgroundColor: ORANGE_400
  1977. });
  1978. }
  1979. if (route.__vd_match) {
  1980. tags.push({
  1981. label: "matches",
  1982. textColor: 0,
  1983. backgroundColor: PINK_500
  1984. });
  1985. }
  1986. if (route.__vd_exactActive) {
  1987. tags.push({
  1988. label: "exact",
  1989. textColor: 0,
  1990. backgroundColor: LIME_500
  1991. });
  1992. }
  1993. if (route.__vd_active) {
  1994. tags.push({
  1995. label: "active",
  1996. textColor: 0,
  1997. backgroundColor: BLUE_600
  1998. });
  1999. }
  2000. if (record.redirect) {
  2001. tags.push({
  2002. label: typeof record.redirect === "string" ? `redirect: ${record.redirect}` : "redirects",
  2003. textColor: 16777215,
  2004. backgroundColor: DARK
  2005. });
  2006. }
  2007. let id = record.__vd_id;
  2008. if (id == null) {
  2009. id = String(routeRecordId++);
  2010. record.__vd_id = id;
  2011. }
  2012. return {
  2013. id,
  2014. label: record.path,
  2015. tags,
  2016. children: route.children.map(formatRouteRecordForInspector)
  2017. };
  2018. }
  2019. var routeRecordId = 0;
  2020. var EXTRACT_REGEXP_RE = /^\/(.*)\/([a-z]*)$/;
  2021. function markRouteRecordActive(route, currentRoute) {
  2022. const isExactActive = currentRoute.matched.length && isSameRouteRecord(currentRoute.matched[currentRoute.matched.length - 1], route.record);
  2023. route.__vd_exactActive = route.__vd_active = isExactActive;
  2024. if (!isExactActive) {
  2025. route.__vd_active = currentRoute.matched.some((match) => isSameRouteRecord(match, route.record));
  2026. }
  2027. route.children.forEach((childRoute) => markRouteRecordActive(childRoute, currentRoute));
  2028. }
  2029. function resetMatchStateOnRouteRecord(route) {
  2030. route.__vd_match = false;
  2031. route.children.forEach(resetMatchStateOnRouteRecord);
  2032. }
  2033. function isRouteMatching(route, filter) {
  2034. const found = String(route.re).match(EXTRACT_REGEXP_RE);
  2035. route.__vd_match = false;
  2036. if (!found || found.length < 3) {
  2037. return false;
  2038. }
  2039. const nonEndingRE = new RegExp(found[1].replace(/\$$/, ""), found[2]);
  2040. if (nonEndingRE.test(filter)) {
  2041. route.children.forEach((child) => isRouteMatching(child, filter));
  2042. if (route.record.path !== "/" || filter === "/") {
  2043. route.__vd_match = route.re.test(filter);
  2044. return true;
  2045. }
  2046. return false;
  2047. }
  2048. const path = route.record.path.toLowerCase();
  2049. const decodedPath = decode(path);
  2050. if (!filter.startsWith("/") && (decodedPath.includes(filter) || path.includes(filter)))
  2051. return true;
  2052. if (decodedPath.startsWith(filter) || path.startsWith(filter))
  2053. return true;
  2054. if (route.record.name && String(route.record.name).includes(filter))
  2055. return true;
  2056. return route.children.some((child) => isRouteMatching(child, filter));
  2057. }
  2058. function omit(obj, keys) {
  2059. const ret = {};
  2060. for (const key in obj) {
  2061. if (!keys.includes(key)) {
  2062. ret[key] = obj[key];
  2063. }
  2064. }
  2065. return ret;
  2066. }
  2067. function createRouter(options) {
  2068. const matcher = createRouterMatcher(options.routes, options);
  2069. const parseQuery$1 = options.parseQuery || parseQuery;
  2070. const stringifyQuery$1 = options.stringifyQuery || stringifyQuery;
  2071. const routerHistory = options.history;
  2072. if (!routerHistory)
  2073. throw new Error('Provide the "history" option when calling "createRouter()": https://next.router.vuejs.org/api/#history.');
  2074. const beforeGuards = useCallbacks();
  2075. const beforeResolveGuards = useCallbacks();
  2076. const afterGuards = useCallbacks();
  2077. const currentRoute = shallowRef(START_LOCATION_NORMALIZED);
  2078. let pendingLocation = START_LOCATION_NORMALIZED;
  2079. if (isBrowser && options.scrollBehavior && "scrollRestoration" in history) {
  2080. history.scrollRestoration = "manual";
  2081. }
  2082. const normalizeParams = applyToParams.bind(null, (paramValue) => "" + paramValue);
  2083. const encodeParams = applyToParams.bind(null, encodeParam);
  2084. const decodeParams = (
  2085. // @ts-expect-error: intentionally avoid the type check
  2086. applyToParams.bind(null, decode)
  2087. );
  2088. function addRoute(parentOrRoute, route) {
  2089. let parent;
  2090. let record;
  2091. if (isRouteName(parentOrRoute)) {
  2092. parent = matcher.getRecordMatcher(parentOrRoute);
  2093. record = route;
  2094. } else {
  2095. record = parentOrRoute;
  2096. }
  2097. return matcher.addRoute(record, parent);
  2098. }
  2099. function removeRoute(name) {
  2100. const recordMatcher = matcher.getRecordMatcher(name);
  2101. if (recordMatcher) {
  2102. matcher.removeRoute(recordMatcher);
  2103. } else if (true) {
  2104. warn(`Cannot remove non-existent route "${String(name)}"`);
  2105. }
  2106. }
  2107. function getRoutes() {
  2108. return matcher.getRoutes().map((routeMatcher) => routeMatcher.record);
  2109. }
  2110. function hasRoute(name) {
  2111. return !!matcher.getRecordMatcher(name);
  2112. }
  2113. function resolve(rawLocation, currentLocation) {
  2114. currentLocation = assign({}, currentLocation || currentRoute.value);
  2115. if (typeof rawLocation === "string") {
  2116. const locationNormalized = parseURL(parseQuery$1, rawLocation, currentLocation.path);
  2117. const matchedRoute2 = matcher.resolve({ path: locationNormalized.path }, currentLocation);
  2118. const href2 = routerHistory.createHref(locationNormalized.fullPath);
  2119. if (true) {
  2120. if (href2.startsWith("//"))
  2121. warn(`Location "${rawLocation}" resolved to "${href2}". A resolved location cannot start with multiple slashes.`);
  2122. else if (!matchedRoute2.matched.length) {
  2123. warn(`No match found for location with path "${rawLocation}"`);
  2124. }
  2125. }
  2126. return assign(locationNormalized, matchedRoute2, {
  2127. params: decodeParams(matchedRoute2.params),
  2128. hash: decode(locationNormalized.hash),
  2129. redirectedFrom: void 0,
  2130. href: href2
  2131. });
  2132. }
  2133. let matcherLocation;
  2134. if ("path" in rawLocation) {
  2135. if ("params" in rawLocation && !("name" in rawLocation) && // @ts-expect-error: the type is never
  2136. Object.keys(rawLocation.params).length) {
  2137. warn(`Path "${// @ts-expect-error: the type is never
  2138. rawLocation.path}" was passed with params but they will be ignored. Use a named route alongside params instead.`);
  2139. }
  2140. matcherLocation = assign({}, rawLocation, {
  2141. path: parseURL(parseQuery$1, rawLocation.path, currentLocation.path).path
  2142. });
  2143. } else {
  2144. const targetParams = assign({}, rawLocation.params);
  2145. for (const key in targetParams) {
  2146. if (targetParams[key] == null) {
  2147. delete targetParams[key];
  2148. }
  2149. }
  2150. matcherLocation = assign({}, rawLocation, {
  2151. params: encodeParams(rawLocation.params)
  2152. });
  2153. currentLocation.params = encodeParams(currentLocation.params);
  2154. }
  2155. const matchedRoute = matcher.resolve(matcherLocation, currentLocation);
  2156. const hash = rawLocation.hash || "";
  2157. if (hash && !hash.startsWith("#")) {
  2158. warn(`A \`hash\` should always start with the character "#". Replace "${hash}" with "#${hash}".`);
  2159. }
  2160. matchedRoute.params = normalizeParams(decodeParams(matchedRoute.params));
  2161. const fullPath = stringifyURL(stringifyQuery$1, assign({}, rawLocation, {
  2162. hash: encodeHash(hash),
  2163. path: matchedRoute.path
  2164. }));
  2165. const href = routerHistory.createHref(fullPath);
  2166. if (true) {
  2167. if (href.startsWith("//")) {
  2168. warn(`Location "${rawLocation}" resolved to "${href}". A resolved location cannot start with multiple slashes.`);
  2169. } else if (!matchedRoute.matched.length) {
  2170. warn(`No match found for location with path "${"path" in rawLocation ? rawLocation.path : rawLocation}"`);
  2171. }
  2172. }
  2173. return assign({
  2174. fullPath,
  2175. // keep the hash encoded so fullPath is effectively path + encodedQuery +
  2176. // hash
  2177. hash,
  2178. query: (
  2179. // if the user is using a custom query lib like qs, we might have
  2180. // nested objects, so we keep the query as is, meaning it can contain
  2181. // numbers at `$route.query`, but at the point, the user will have to
  2182. // use their own type anyway.
  2183. // https://github.com/vuejs/router/issues/328#issuecomment-649481567
  2184. stringifyQuery$1 === stringifyQuery ? normalizeQuery(rawLocation.query) : rawLocation.query || {}
  2185. )
  2186. }, matchedRoute, {
  2187. redirectedFrom: void 0,
  2188. href
  2189. });
  2190. }
  2191. function locationAsObject(to) {
  2192. return typeof to === "string" ? parseURL(parseQuery$1, to, currentRoute.value.path) : assign({}, to);
  2193. }
  2194. function checkCanceledNavigation(to, from) {
  2195. if (pendingLocation !== to) {
  2196. return createRouterError(8, {
  2197. from,
  2198. to
  2199. });
  2200. }
  2201. }
  2202. function push(to) {
  2203. return pushWithRedirect(to);
  2204. }
  2205. function replace(to) {
  2206. return push(assign(locationAsObject(to), { replace: true }));
  2207. }
  2208. function handleRedirectRecord(to) {
  2209. const lastMatched = to.matched[to.matched.length - 1];
  2210. if (lastMatched && lastMatched.redirect) {
  2211. const { redirect } = lastMatched;
  2212. let newTargetLocation = typeof redirect === "function" ? redirect(to) : redirect;
  2213. if (typeof newTargetLocation === "string") {
  2214. newTargetLocation = newTargetLocation.includes("?") || newTargetLocation.includes("#") ? newTargetLocation = locationAsObject(newTargetLocation) : (
  2215. // force empty params
  2216. { path: newTargetLocation }
  2217. );
  2218. newTargetLocation.params = {};
  2219. }
  2220. if (!("path" in newTargetLocation) && !("name" in newTargetLocation)) {
  2221. warn(`Invalid redirect found:
  2222. ${JSON.stringify(newTargetLocation, null, 2)}
  2223. when navigating to "${to.fullPath}". A redirect must contain a name or path. This will break in production.`);
  2224. throw new Error("Invalid redirect");
  2225. }
  2226. return assign({
  2227. query: to.query,
  2228. hash: to.hash,
  2229. // avoid transferring params if the redirect has a path
  2230. params: "path" in newTargetLocation ? {} : to.params
  2231. }, newTargetLocation);
  2232. }
  2233. }
  2234. function pushWithRedirect(to, redirectedFrom) {
  2235. const targetLocation = pendingLocation = resolve(to);
  2236. const from = currentRoute.value;
  2237. const data = to.state;
  2238. const force = to.force;
  2239. const replace2 = to.replace === true;
  2240. const shouldRedirect = handleRedirectRecord(targetLocation);
  2241. if (shouldRedirect)
  2242. return pushWithRedirect(
  2243. assign(locationAsObject(shouldRedirect), {
  2244. state: typeof shouldRedirect === "object" ? assign({}, data, shouldRedirect.state) : data,
  2245. force,
  2246. replace: replace2
  2247. }),
  2248. // keep original redirectedFrom if it exists
  2249. redirectedFrom || targetLocation
  2250. );
  2251. const toLocation = targetLocation;
  2252. toLocation.redirectedFrom = redirectedFrom;
  2253. let failure;
  2254. if (!force && isSameRouteLocation(stringifyQuery$1, from, targetLocation)) {
  2255. failure = createRouterError(16, { to: toLocation, from });
  2256. handleScroll(
  2257. from,
  2258. from,
  2259. // this is a push, the only way for it to be triggered from a
  2260. // history.listen is with a redirect, which makes it become a push
  2261. true,
  2262. // This cannot be the first navigation because the initial location
  2263. // cannot be manually navigated to
  2264. false
  2265. );
  2266. }
  2267. return (failure ? Promise.resolve(failure) : navigate(toLocation, from)).catch((error) => isNavigationFailure(error) ? (
  2268. // navigation redirects still mark the router as ready
  2269. isNavigationFailure(
  2270. error,
  2271. 2
  2272. /* ErrorTypes.NAVIGATION_GUARD_REDIRECT */
  2273. ) ? error : markAsReady(error)
  2274. ) : (
  2275. // reject any unknown error
  2276. triggerError(error, toLocation, from)
  2277. )).then((failure2) => {
  2278. if (failure2) {
  2279. if (isNavigationFailure(
  2280. failure2,
  2281. 2
  2282. /* ErrorTypes.NAVIGATION_GUARD_REDIRECT */
  2283. )) {
  2284. if (// we are redirecting to the same location we were already at
  2285. isSameRouteLocation(stringifyQuery$1, resolve(failure2.to), toLocation) && // and we have done it a couple of times
  2286. redirectedFrom && // @ts-expect-error: added only in dev
  2287. (redirectedFrom._count = redirectedFrom._count ? (
  2288. // @ts-expect-error
  2289. redirectedFrom._count + 1
  2290. ) : 1) > 10) {
  2291. warn(`Detected an infinite redirection in a navigation guard when going from "${from.fullPath}" to "${toLocation.fullPath}". Aborting to avoid a Stack Overflow. This will break in production if not fixed.`);
  2292. return Promise.reject(new Error("Infinite redirect in navigation guard"));
  2293. }
  2294. return pushWithRedirect(
  2295. // keep options
  2296. assign({
  2297. // preserve an existing replacement but allow the redirect to override it
  2298. replace: replace2
  2299. }, locationAsObject(failure2.to), {
  2300. state: typeof failure2.to === "object" ? assign({}, data, failure2.to.state) : data,
  2301. force
  2302. }),
  2303. // preserve the original redirectedFrom if any
  2304. redirectedFrom || toLocation
  2305. );
  2306. }
  2307. } else {
  2308. failure2 = finalizeNavigation(toLocation, from, true, replace2, data);
  2309. }
  2310. triggerAfterEach(toLocation, from, failure2);
  2311. return failure2;
  2312. });
  2313. }
  2314. function checkCanceledNavigationAndReject(to, from) {
  2315. const error = checkCanceledNavigation(to, from);
  2316. return error ? Promise.reject(error) : Promise.resolve();
  2317. }
  2318. function navigate(to, from) {
  2319. let guards;
  2320. const [leavingRecords, updatingRecords, enteringRecords] = extractChangingRecords(to, from);
  2321. guards = extractComponentsGuards(leavingRecords.reverse(), "beforeRouteLeave", to, from);
  2322. for (const record of leavingRecords) {
  2323. record.leaveGuards.forEach((guard) => {
  2324. guards.push(guardToPromiseFn(guard, to, from));
  2325. });
  2326. }
  2327. const canceledNavigationCheck = checkCanceledNavigationAndReject.bind(null, to, from);
  2328. guards.push(canceledNavigationCheck);
  2329. return runGuardQueue(guards).then(() => {
  2330. guards = [];
  2331. for (const guard of beforeGuards.list()) {
  2332. guards.push(guardToPromiseFn(guard, to, from));
  2333. }
  2334. guards.push(canceledNavigationCheck);
  2335. return runGuardQueue(guards);
  2336. }).then(() => {
  2337. guards = extractComponentsGuards(updatingRecords, "beforeRouteUpdate", to, from);
  2338. for (const record of updatingRecords) {
  2339. record.updateGuards.forEach((guard) => {
  2340. guards.push(guardToPromiseFn(guard, to, from));
  2341. });
  2342. }
  2343. guards.push(canceledNavigationCheck);
  2344. return runGuardQueue(guards);
  2345. }).then(() => {
  2346. guards = [];
  2347. for (const record of to.matched) {
  2348. if (record.beforeEnter && !from.matched.includes(record)) {
  2349. if (isArray(record.beforeEnter)) {
  2350. for (const beforeEnter of record.beforeEnter)
  2351. guards.push(guardToPromiseFn(beforeEnter, to, from));
  2352. } else {
  2353. guards.push(guardToPromiseFn(record.beforeEnter, to, from));
  2354. }
  2355. }
  2356. }
  2357. guards.push(canceledNavigationCheck);
  2358. return runGuardQueue(guards);
  2359. }).then(() => {
  2360. to.matched.forEach((record) => record.enterCallbacks = {});
  2361. guards = extractComponentsGuards(enteringRecords, "beforeRouteEnter", to, from);
  2362. guards.push(canceledNavigationCheck);
  2363. return runGuardQueue(guards);
  2364. }).then(() => {
  2365. guards = [];
  2366. for (const guard of beforeResolveGuards.list()) {
  2367. guards.push(guardToPromiseFn(guard, to, from));
  2368. }
  2369. guards.push(canceledNavigationCheck);
  2370. return runGuardQueue(guards);
  2371. }).catch((err) => isNavigationFailure(
  2372. err,
  2373. 8
  2374. /* ErrorTypes.NAVIGATION_CANCELLED */
  2375. ) ? err : Promise.reject(err));
  2376. }
  2377. function triggerAfterEach(to, from, failure) {
  2378. for (const guard of afterGuards.list())
  2379. guard(to, from, failure);
  2380. }
  2381. function finalizeNavigation(toLocation, from, isPush, replace2, data) {
  2382. const error = checkCanceledNavigation(toLocation, from);
  2383. if (error)
  2384. return error;
  2385. const isFirstNavigation = from === START_LOCATION_NORMALIZED;
  2386. const state = !isBrowser ? {} : history.state;
  2387. if (isPush) {
  2388. if (replace2 || isFirstNavigation)
  2389. routerHistory.replace(toLocation.fullPath, assign({
  2390. scroll: isFirstNavigation && state && state.scroll
  2391. }, data));
  2392. else
  2393. routerHistory.push(toLocation.fullPath, data);
  2394. }
  2395. currentRoute.value = toLocation;
  2396. handleScroll(toLocation, from, isPush, isFirstNavigation);
  2397. markAsReady();
  2398. }
  2399. let removeHistoryListener;
  2400. function setupListeners() {
  2401. if (removeHistoryListener)
  2402. return;
  2403. removeHistoryListener = routerHistory.listen((to, _from, info) => {
  2404. if (!router.listening)
  2405. return;
  2406. const toLocation = resolve(to);
  2407. const shouldRedirect = handleRedirectRecord(toLocation);
  2408. if (shouldRedirect) {
  2409. pushWithRedirect(assign(shouldRedirect, { replace: true }), toLocation).catch(noop);
  2410. return;
  2411. }
  2412. pendingLocation = toLocation;
  2413. const from = currentRoute.value;
  2414. if (isBrowser) {
  2415. saveScrollPosition(getScrollKey(from.fullPath, info.delta), computeScrollPosition());
  2416. }
  2417. navigate(toLocation, from).catch((error) => {
  2418. if (isNavigationFailure(
  2419. error,
  2420. 4 | 8
  2421. /* ErrorTypes.NAVIGATION_CANCELLED */
  2422. )) {
  2423. return error;
  2424. }
  2425. if (isNavigationFailure(
  2426. error,
  2427. 2
  2428. /* ErrorTypes.NAVIGATION_GUARD_REDIRECT */
  2429. )) {
  2430. pushWithRedirect(
  2431. error.to,
  2432. toLocation
  2433. // avoid an uncaught rejection, let push call triggerError
  2434. ).then((failure) => {
  2435. if (isNavigationFailure(
  2436. failure,
  2437. 4 | 16
  2438. /* ErrorTypes.NAVIGATION_DUPLICATED */
  2439. ) && !info.delta && info.type === NavigationType.pop) {
  2440. routerHistory.go(-1, false);
  2441. }
  2442. }).catch(noop);
  2443. return Promise.reject();
  2444. }
  2445. if (info.delta) {
  2446. routerHistory.go(-info.delta, false);
  2447. }
  2448. return triggerError(error, toLocation, from);
  2449. }).then((failure) => {
  2450. failure = failure || finalizeNavigation(
  2451. // after navigation, all matched components are resolved
  2452. toLocation,
  2453. from,
  2454. false
  2455. );
  2456. if (failure) {
  2457. if (info.delta && // a new navigation has been triggered, so we do not want to revert, that will change the current history
  2458. // entry while a different route is displayed
  2459. !isNavigationFailure(
  2460. failure,
  2461. 8
  2462. /* ErrorTypes.NAVIGATION_CANCELLED */
  2463. )) {
  2464. routerHistory.go(-info.delta, false);
  2465. } else if (info.type === NavigationType.pop && isNavigationFailure(
  2466. failure,
  2467. 4 | 16
  2468. /* ErrorTypes.NAVIGATION_DUPLICATED */
  2469. )) {
  2470. routerHistory.go(-1, false);
  2471. }
  2472. }
  2473. triggerAfterEach(toLocation, from, failure);
  2474. }).catch(noop);
  2475. });
  2476. }
  2477. let readyHandlers = useCallbacks();
  2478. let errorHandlers = useCallbacks();
  2479. let ready;
  2480. function triggerError(error, to, from) {
  2481. markAsReady(error);
  2482. const list = errorHandlers.list();
  2483. if (list.length) {
  2484. list.forEach((handler) => handler(error, to, from));
  2485. } else {
  2486. if (true) {
  2487. warn("uncaught error during route navigation:");
  2488. }
  2489. console.error(error);
  2490. }
  2491. return Promise.reject(error);
  2492. }
  2493. function isReady() {
  2494. if (ready && currentRoute.value !== START_LOCATION_NORMALIZED)
  2495. return Promise.resolve();
  2496. return new Promise((resolve2, reject) => {
  2497. readyHandlers.add([resolve2, reject]);
  2498. });
  2499. }
  2500. function markAsReady(err) {
  2501. if (!ready) {
  2502. ready = !err;
  2503. setupListeners();
  2504. readyHandlers.list().forEach(([resolve2, reject]) => err ? reject(err) : resolve2());
  2505. readyHandlers.reset();
  2506. }
  2507. return err;
  2508. }
  2509. function handleScroll(to, from, isPush, isFirstNavigation) {
  2510. const { scrollBehavior } = options;
  2511. if (!isBrowser || !scrollBehavior)
  2512. return Promise.resolve();
  2513. const scrollPosition = !isPush && getSavedScrollPosition(getScrollKey(to.fullPath, 0)) || (isFirstNavigation || !isPush) && history.state && history.state.scroll || null;
  2514. return nextTick().then(() => scrollBehavior(to, from, scrollPosition)).then((position) => position && scrollToPosition(position)).catch((err) => triggerError(err, to, from));
  2515. }
  2516. const go = (delta) => routerHistory.go(delta);
  2517. let started;
  2518. const installedApps = /* @__PURE__ */ new Set();
  2519. const router = {
  2520. currentRoute,
  2521. listening: true,
  2522. addRoute,
  2523. removeRoute,
  2524. hasRoute,
  2525. getRoutes,
  2526. resolve,
  2527. options,
  2528. push,
  2529. replace,
  2530. go,
  2531. back: () => go(-1),
  2532. forward: () => go(1),
  2533. beforeEach: beforeGuards.add,
  2534. beforeResolve: beforeResolveGuards.add,
  2535. afterEach: afterGuards.add,
  2536. onError: errorHandlers.add,
  2537. isReady,
  2538. install(app) {
  2539. const router2 = this;
  2540. app.component("RouterLink", RouterLink);
  2541. app.component("RouterView", RouterView);
  2542. app.config.globalProperties.$router = router2;
  2543. Object.defineProperty(app.config.globalProperties, "$route", {
  2544. enumerable: true,
  2545. get: () => unref(currentRoute)
  2546. });
  2547. if (isBrowser && // used for the initial navigation client side to avoid pushing
  2548. // multiple times when the router is used in multiple apps
  2549. !started && currentRoute.value === START_LOCATION_NORMALIZED) {
  2550. started = true;
  2551. push(routerHistory.location).catch((err) => {
  2552. if (true)
  2553. warn("Unexpected error when starting the router:", err);
  2554. });
  2555. }
  2556. const reactiveRoute = {};
  2557. for (const key in START_LOCATION_NORMALIZED) {
  2558. reactiveRoute[key] = computed(() => currentRoute.value[key]);
  2559. }
  2560. app.provide(routerKey, router2);
  2561. app.provide(routeLocationKey, reactive(reactiveRoute));
  2562. app.provide(routerViewLocationKey, currentRoute);
  2563. const unmountApp = app.unmount;
  2564. installedApps.add(app);
  2565. app.unmount = function() {
  2566. installedApps.delete(app);
  2567. if (installedApps.size < 1) {
  2568. pendingLocation = START_LOCATION_NORMALIZED;
  2569. removeHistoryListener && removeHistoryListener();
  2570. removeHistoryListener = null;
  2571. currentRoute.value = START_LOCATION_NORMALIZED;
  2572. started = false;
  2573. ready = false;
  2574. }
  2575. unmountApp();
  2576. };
  2577. if (isBrowser) {
  2578. addDevtools(app, router2, matcher);
  2579. }
  2580. }
  2581. };
  2582. return router;
  2583. }
  2584. function runGuardQueue(guards) {
  2585. return guards.reduce((promise, guard) => promise.then(() => guard()), Promise.resolve());
  2586. }
  2587. function extractChangingRecords(to, from) {
  2588. const leavingRecords = [];
  2589. const updatingRecords = [];
  2590. const enteringRecords = [];
  2591. const len = Math.max(from.matched.length, to.matched.length);
  2592. for (let i = 0; i < len; i++) {
  2593. const recordFrom = from.matched[i];
  2594. if (recordFrom) {
  2595. if (to.matched.find((record) => isSameRouteRecord(record, recordFrom)))
  2596. updatingRecords.push(recordFrom);
  2597. else
  2598. leavingRecords.push(recordFrom);
  2599. }
  2600. const recordTo = to.matched[i];
  2601. if (recordTo) {
  2602. if (!from.matched.find((record) => isSameRouteRecord(record, recordTo))) {
  2603. enteringRecords.push(recordTo);
  2604. }
  2605. }
  2606. }
  2607. return [leavingRecords, updatingRecords, enteringRecords];
  2608. }
  2609. function useRouter() {
  2610. return inject(routerKey);
  2611. }
  2612. function useRoute() {
  2613. return inject(routeLocationKey);
  2614. }
  2615. export {
  2616. NavigationFailureType,
  2617. RouterLink,
  2618. RouterView,
  2619. START_LOCATION_NORMALIZED as START_LOCATION,
  2620. createMemoryHistory,
  2621. createRouter,
  2622. createRouterMatcher,
  2623. createWebHashHistory,
  2624. createWebHistory,
  2625. isNavigationFailure,
  2626. loadRouteLocation,
  2627. matchedRouteKey,
  2628. onBeforeRouteLeave,
  2629. onBeforeRouteUpdate,
  2630. parseQuery,
  2631. routeLocationKey,
  2632. routerKey,
  2633. routerViewLocationKey,
  2634. stringifyQuery,
  2635. useLink,
  2636. useRoute,
  2637. useRouter,
  2638. viewDepthKey
  2639. };
  2640. /*! Bundled license information:
  2641. vue-router/dist/vue-router.mjs:
  2642. (*!
  2643. * vue-router v4.1.6
  2644. * (c) 2022 Eduardo San Martin Morote
  2645. * @license MIT
  2646. *)
  2647. */
  2648. //# sourceMappingURL=vue-router.js.map