router.umd.js 256 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/platform-browser')) :
  8. typeof define === 'function' && define.amd ? define('@angular/router', ['exports', '@angular/common', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/platform-browser'], factory) :
  9. (global = global || self, factory((global.ng = global.ng || {}, global.ng.router = {}), global.ng.common, global.ng.core, global.rxjs, global.rxjs.operators, global.ng.platformBrowser));
  10. }(this, function (exports, common, core, rxjs, operators, platformBrowser) { 'use strict';
  11. /*! *****************************************************************************
  12. Copyright (c) Microsoft Corporation. All rights reserved.
  13. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  14. this file except in compliance with the License. You may obtain a copy of the
  15. License at http://www.apache.org/licenses/LICENSE-2.0
  16. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  18. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  19. MERCHANTABLITY OR NON-INFRINGEMENT.
  20. See the Apache Version 2.0 License for specific language governing permissions
  21. and limitations under the License.
  22. ***************************************************************************** */
  23. /* global Reflect, Promise */
  24. var extendStatics = function(d, b) {
  25. extendStatics = Object.setPrototypeOf ||
  26. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  27. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  28. return extendStatics(d, b);
  29. };
  30. function __extends(d, b) {
  31. extendStatics(d, b);
  32. function __() { this.constructor = d; }
  33. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  34. }
  35. var __assign = function() {
  36. __assign = Object.assign || function __assign(t) {
  37. for (var s, i = 1, n = arguments.length; i < n; i++) {
  38. s = arguments[i];
  39. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  40. }
  41. return t;
  42. };
  43. return __assign.apply(this, arguments);
  44. };
  45. function __decorate(decorators, target, key, desc) {
  46. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  47. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  48. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  49. return c > 3 && r && Object.defineProperty(target, key, r), r;
  50. }
  51. function __param(paramIndex, decorator) {
  52. return function (target, key) { decorator(target, key, paramIndex); }
  53. }
  54. function __metadata(metadataKey, metadataValue) {
  55. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  56. }
  57. function __values(o) {
  58. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  59. if (m) return m.call(o);
  60. return {
  61. next: function () {
  62. if (o && i >= o.length) o = void 0;
  63. return { value: o && o[i++], done: !o };
  64. }
  65. };
  66. }
  67. function __read(o, n) {
  68. var m = typeof Symbol === "function" && o[Symbol.iterator];
  69. if (!m) return o;
  70. var i = m.call(o), r, ar = [], e;
  71. try {
  72. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  73. }
  74. catch (error) { e = { error: error }; }
  75. finally {
  76. try {
  77. if (r && !r.done && (m = i["return"])) m.call(i);
  78. }
  79. finally { if (e) throw e.error; }
  80. }
  81. return ar;
  82. }
  83. function __spread() {
  84. for (var ar = [], i = 0; i < arguments.length; i++)
  85. ar = ar.concat(__read(arguments[i]));
  86. return ar;
  87. }
  88. /**
  89. * @license
  90. * Copyright Google Inc. All Rights Reserved.
  91. *
  92. * Use of this source code is governed by an MIT-style license that can be
  93. * found in the LICENSE file at https://angular.io/license
  94. */
  95. /**
  96. * @description
  97. *
  98. * Base for events the Router goes through, as opposed to events tied to a specific
  99. * Route. `RouterEvent`s will only be fired one time for any given navigation.
  100. *
  101. * Example:
  102. *
  103. * ```
  104. * class MyService {
  105. * constructor(public router: Router, logger: Logger) {
  106. * router.events.pipe(
  107. * filter(e => e instanceof RouterEvent)
  108. * ).subscribe(e => {
  109. * logger.log(e.id, e.url);
  110. * });
  111. * }
  112. * }
  113. * ```
  114. *
  115. * @publicApi
  116. */
  117. var RouterEvent = /** @class */ (function () {
  118. function RouterEvent(
  119. /** @docsNotRequired */
  120. id,
  121. /** @docsNotRequired */
  122. url) {
  123. this.id = id;
  124. this.url = url;
  125. }
  126. return RouterEvent;
  127. }());
  128. /**
  129. * @description
  130. *
  131. * Represents an event triggered when a navigation starts.
  132. *
  133. * @publicApi
  134. */
  135. var NavigationStart = /** @class */ (function (_super) {
  136. __extends(NavigationStart, _super);
  137. function NavigationStart(
  138. /** @docsNotRequired */
  139. id,
  140. /** @docsNotRequired */
  141. url,
  142. /** @docsNotRequired */
  143. navigationTrigger,
  144. /** @docsNotRequired */
  145. restoredState) {
  146. if (navigationTrigger === void 0) { navigationTrigger = 'imperative'; }
  147. if (restoredState === void 0) { restoredState = null; }
  148. var _this = _super.call(this, id, url) || this;
  149. _this.navigationTrigger = navigationTrigger;
  150. _this.restoredState = restoredState;
  151. return _this;
  152. }
  153. /** @docsNotRequired */
  154. NavigationStart.prototype.toString = function () { return "NavigationStart(id: " + this.id + ", url: '" + this.url + "')"; };
  155. return NavigationStart;
  156. }(RouterEvent));
  157. /**
  158. * @description
  159. *
  160. * Represents an event triggered when a navigation ends successfully.
  161. *
  162. * @publicApi
  163. */
  164. var NavigationEnd = /** @class */ (function (_super) {
  165. __extends(NavigationEnd, _super);
  166. function NavigationEnd(
  167. /** @docsNotRequired */
  168. id,
  169. /** @docsNotRequired */
  170. url,
  171. /** @docsNotRequired */
  172. urlAfterRedirects) {
  173. var _this = _super.call(this, id, url) || this;
  174. _this.urlAfterRedirects = urlAfterRedirects;
  175. return _this;
  176. }
  177. /** @docsNotRequired */
  178. NavigationEnd.prototype.toString = function () {
  179. return "NavigationEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "')";
  180. };
  181. return NavigationEnd;
  182. }(RouterEvent));
  183. /**
  184. * @description
  185. *
  186. * Represents an event triggered when a navigation is canceled.
  187. *
  188. * @publicApi
  189. */
  190. var NavigationCancel = /** @class */ (function (_super) {
  191. __extends(NavigationCancel, _super);
  192. function NavigationCancel(
  193. /** @docsNotRequired */
  194. id,
  195. /** @docsNotRequired */
  196. url,
  197. /** @docsNotRequired */
  198. reason) {
  199. var _this = _super.call(this, id, url) || this;
  200. _this.reason = reason;
  201. return _this;
  202. }
  203. /** @docsNotRequired */
  204. NavigationCancel.prototype.toString = function () { return "NavigationCancel(id: " + this.id + ", url: '" + this.url + "')"; };
  205. return NavigationCancel;
  206. }(RouterEvent));
  207. /**
  208. * @description
  209. *
  210. * Represents an event triggered when a navigation fails due to an unexpected error.
  211. *
  212. * @publicApi
  213. */
  214. var NavigationError = /** @class */ (function (_super) {
  215. __extends(NavigationError, _super);
  216. function NavigationError(
  217. /** @docsNotRequired */
  218. id,
  219. /** @docsNotRequired */
  220. url,
  221. /** @docsNotRequired */
  222. error) {
  223. var _this = _super.call(this, id, url) || this;
  224. _this.error = error;
  225. return _this;
  226. }
  227. /** @docsNotRequired */
  228. NavigationError.prototype.toString = function () {
  229. return "NavigationError(id: " + this.id + ", url: '" + this.url + "', error: " + this.error + ")";
  230. };
  231. return NavigationError;
  232. }(RouterEvent));
  233. /**
  234. * @description
  235. *
  236. * Represents an event triggered when routes are recognized.
  237. *
  238. * @publicApi
  239. */
  240. var RoutesRecognized = /** @class */ (function (_super) {
  241. __extends(RoutesRecognized, _super);
  242. function RoutesRecognized(
  243. /** @docsNotRequired */
  244. id,
  245. /** @docsNotRequired */
  246. url,
  247. /** @docsNotRequired */
  248. urlAfterRedirects,
  249. /** @docsNotRequired */
  250. state) {
  251. var _this = _super.call(this, id, url) || this;
  252. _this.urlAfterRedirects = urlAfterRedirects;
  253. _this.state = state;
  254. return _this;
  255. }
  256. /** @docsNotRequired */
  257. RoutesRecognized.prototype.toString = function () {
  258. return "RoutesRecognized(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
  259. };
  260. return RoutesRecognized;
  261. }(RouterEvent));
  262. /**
  263. * @description
  264. *
  265. * Represents the start of the Guard phase of routing.
  266. *
  267. * @publicApi
  268. */
  269. var GuardsCheckStart = /** @class */ (function (_super) {
  270. __extends(GuardsCheckStart, _super);
  271. function GuardsCheckStart(
  272. /** @docsNotRequired */
  273. id,
  274. /** @docsNotRequired */
  275. url,
  276. /** @docsNotRequired */
  277. urlAfterRedirects,
  278. /** @docsNotRequired */
  279. state) {
  280. var _this = _super.call(this, id, url) || this;
  281. _this.urlAfterRedirects = urlAfterRedirects;
  282. _this.state = state;
  283. return _this;
  284. }
  285. GuardsCheckStart.prototype.toString = function () {
  286. return "GuardsCheckStart(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
  287. };
  288. return GuardsCheckStart;
  289. }(RouterEvent));
  290. /**
  291. * @description
  292. *
  293. * Represents the end of the Guard phase of routing.
  294. *
  295. * @publicApi
  296. */
  297. var GuardsCheckEnd = /** @class */ (function (_super) {
  298. __extends(GuardsCheckEnd, _super);
  299. function GuardsCheckEnd(
  300. /** @docsNotRequired */
  301. id,
  302. /** @docsNotRequired */
  303. url,
  304. /** @docsNotRequired */
  305. urlAfterRedirects,
  306. /** @docsNotRequired */
  307. state,
  308. /** @docsNotRequired */
  309. shouldActivate) {
  310. var _this = _super.call(this, id, url) || this;
  311. _this.urlAfterRedirects = urlAfterRedirects;
  312. _this.state = state;
  313. _this.shouldActivate = shouldActivate;
  314. return _this;
  315. }
  316. GuardsCheckEnd.prototype.toString = function () {
  317. return "GuardsCheckEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ", shouldActivate: " + this.shouldActivate + ")";
  318. };
  319. return GuardsCheckEnd;
  320. }(RouterEvent));
  321. /**
  322. * @description
  323. *
  324. * Represents the start of the Resolve phase of routing. The timing of this
  325. * event may change, thus it's experimental. In the current iteration it will run
  326. * in the "resolve" phase whether there's things to resolve or not. In the future this
  327. * behavior may change to only run when there are things to be resolved.
  328. *
  329. * @publicApi
  330. */
  331. var ResolveStart = /** @class */ (function (_super) {
  332. __extends(ResolveStart, _super);
  333. function ResolveStart(
  334. /** @docsNotRequired */
  335. id,
  336. /** @docsNotRequired */
  337. url,
  338. /** @docsNotRequired */
  339. urlAfterRedirects,
  340. /** @docsNotRequired */
  341. state) {
  342. var _this = _super.call(this, id, url) || this;
  343. _this.urlAfterRedirects = urlAfterRedirects;
  344. _this.state = state;
  345. return _this;
  346. }
  347. ResolveStart.prototype.toString = function () {
  348. return "ResolveStart(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
  349. };
  350. return ResolveStart;
  351. }(RouterEvent));
  352. /**
  353. * @description
  354. *
  355. * Represents the end of the Resolve phase of routing. See note on
  356. * `ResolveStart` for use of this experimental API.
  357. *
  358. * @publicApi
  359. */
  360. var ResolveEnd = /** @class */ (function (_super) {
  361. __extends(ResolveEnd, _super);
  362. function ResolveEnd(
  363. /** @docsNotRequired */
  364. id,
  365. /** @docsNotRequired */
  366. url,
  367. /** @docsNotRequired */
  368. urlAfterRedirects,
  369. /** @docsNotRequired */
  370. state) {
  371. var _this = _super.call(this, id, url) || this;
  372. _this.urlAfterRedirects = urlAfterRedirects;
  373. _this.state = state;
  374. return _this;
  375. }
  376. ResolveEnd.prototype.toString = function () {
  377. return "ResolveEnd(id: " + this.id + ", url: '" + this.url + "', urlAfterRedirects: '" + this.urlAfterRedirects + "', state: " + this.state + ")";
  378. };
  379. return ResolveEnd;
  380. }(RouterEvent));
  381. /**
  382. * @description
  383. *
  384. * Represents an event triggered before lazy loading a route config.
  385. *
  386. * @publicApi
  387. */
  388. var RouteConfigLoadStart = /** @class */ (function () {
  389. function RouteConfigLoadStart(
  390. /** @docsNotRequired */
  391. route) {
  392. this.route = route;
  393. }
  394. RouteConfigLoadStart.prototype.toString = function () { return "RouteConfigLoadStart(path: " + this.route.path + ")"; };
  395. return RouteConfigLoadStart;
  396. }());
  397. /**
  398. * @description
  399. *
  400. * Represents an event triggered when a route has been lazy loaded.
  401. *
  402. * @publicApi
  403. */
  404. var RouteConfigLoadEnd = /** @class */ (function () {
  405. function RouteConfigLoadEnd(
  406. /** @docsNotRequired */
  407. route) {
  408. this.route = route;
  409. }
  410. RouteConfigLoadEnd.prototype.toString = function () { return "RouteConfigLoadEnd(path: " + this.route.path + ")"; };
  411. return RouteConfigLoadEnd;
  412. }());
  413. /**
  414. * @description
  415. *
  416. * Represents the start of end of the Resolve phase of routing. See note on
  417. * `ChildActivationEnd` for use of this experimental API.
  418. *
  419. * @publicApi
  420. */
  421. var ChildActivationStart = /** @class */ (function () {
  422. function ChildActivationStart(
  423. /** @docsNotRequired */
  424. snapshot) {
  425. this.snapshot = snapshot;
  426. }
  427. ChildActivationStart.prototype.toString = function () {
  428. var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
  429. return "ChildActivationStart(path: '" + path + "')";
  430. };
  431. return ChildActivationStart;
  432. }());
  433. /**
  434. * @description
  435. *
  436. * Represents the start of end of the Resolve phase of routing. See note on
  437. * `ChildActivationStart` for use of this experimental API.
  438. *
  439. * @publicApi
  440. */
  441. var ChildActivationEnd = /** @class */ (function () {
  442. function ChildActivationEnd(
  443. /** @docsNotRequired */
  444. snapshot) {
  445. this.snapshot = snapshot;
  446. }
  447. ChildActivationEnd.prototype.toString = function () {
  448. var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
  449. return "ChildActivationEnd(path: '" + path + "')";
  450. };
  451. return ChildActivationEnd;
  452. }());
  453. /**
  454. * @description
  455. *
  456. * Represents the start of end of the Resolve phase of routing. See note on
  457. * `ActivationEnd` for use of this experimental API.
  458. *
  459. * @publicApi
  460. */
  461. var ActivationStart = /** @class */ (function () {
  462. function ActivationStart(
  463. /** @docsNotRequired */
  464. snapshot) {
  465. this.snapshot = snapshot;
  466. }
  467. ActivationStart.prototype.toString = function () {
  468. var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
  469. return "ActivationStart(path: '" + path + "')";
  470. };
  471. return ActivationStart;
  472. }());
  473. /**
  474. * @description
  475. *
  476. * Represents the start of end of the Resolve phase of routing. See note on
  477. * `ActivationStart` for use of this experimental API.
  478. *
  479. * @publicApi
  480. */
  481. var ActivationEnd = /** @class */ (function () {
  482. function ActivationEnd(
  483. /** @docsNotRequired */
  484. snapshot) {
  485. this.snapshot = snapshot;
  486. }
  487. ActivationEnd.prototype.toString = function () {
  488. var path = this.snapshot.routeConfig && this.snapshot.routeConfig.path || '';
  489. return "ActivationEnd(path: '" + path + "')";
  490. };
  491. return ActivationEnd;
  492. }());
  493. /**
  494. * @description
  495. *
  496. * Represents a scrolling event.
  497. *
  498. * @publicApi
  499. */
  500. var Scroll = /** @class */ (function () {
  501. function Scroll(
  502. /** @docsNotRequired */
  503. routerEvent,
  504. /** @docsNotRequired */
  505. position,
  506. /** @docsNotRequired */
  507. anchor) {
  508. this.routerEvent = routerEvent;
  509. this.position = position;
  510. this.anchor = anchor;
  511. }
  512. Scroll.prototype.toString = function () {
  513. var pos = this.position ? this.position[0] + ", " + this.position[1] : null;
  514. return "Scroll(anchor: '" + this.anchor + "', position: '" + pos + "')";
  515. };
  516. return Scroll;
  517. }());
  518. /**
  519. * @license
  520. * Copyright Google Inc. All Rights Reserved.
  521. *
  522. * Use of this source code is governed by an MIT-style license that can be
  523. * found in the LICENSE file at https://angular.io/license
  524. */
  525. /**
  526. * This component is used internally within the router to be a placeholder when an empty
  527. * router-outlet is needed. For example, with a config such as:
  528. *
  529. * `{path: 'parent', outlet: 'nav', children: [...]}`
  530. *
  531. * In order to render, there needs to be a component on this config, which will default
  532. * to this `EmptyOutletComponent`.
  533. */
  534. var ɵEmptyOutletComponent = /** @class */ (function () {
  535. function ɵEmptyOutletComponent() {
  536. }
  537. ɵEmptyOutletComponent = __decorate([
  538. core.Component({ template: "<router-outlet></router-outlet>" })
  539. ], ɵEmptyOutletComponent);
  540. return ɵEmptyOutletComponent;
  541. }());
  542. /**
  543. * @license
  544. * Copyright Google Inc. All Rights Reserved.
  545. *
  546. * Use of this source code is governed by an MIT-style license that can be
  547. * found in the LICENSE file at https://angular.io/license
  548. */
  549. /**
  550. * @description
  551. *
  552. * Name of the primary outlet.
  553. *
  554. * @publicApi
  555. */
  556. var PRIMARY_OUTLET = 'primary';
  557. var ParamsAsMap = /** @class */ (function () {
  558. function ParamsAsMap(params) {
  559. this.params = params || {};
  560. }
  561. ParamsAsMap.prototype.has = function (name) { return this.params.hasOwnProperty(name); };
  562. ParamsAsMap.prototype.get = function (name) {
  563. if (this.has(name)) {
  564. var v = this.params[name];
  565. return Array.isArray(v) ? v[0] : v;
  566. }
  567. return null;
  568. };
  569. ParamsAsMap.prototype.getAll = function (name) {
  570. if (this.has(name)) {
  571. var v = this.params[name];
  572. return Array.isArray(v) ? v : [v];
  573. }
  574. return [];
  575. };
  576. Object.defineProperty(ParamsAsMap.prototype, "keys", {
  577. get: function () { return Object.keys(this.params); },
  578. enumerable: true,
  579. configurable: true
  580. });
  581. return ParamsAsMap;
  582. }());
  583. /**
  584. * Convert a `Params` instance to a `ParamMap`.
  585. *
  586. * @publicApi
  587. */
  588. function convertToParamMap(params) {
  589. return new ParamsAsMap(params);
  590. }
  591. var NAVIGATION_CANCELING_ERROR = 'ngNavigationCancelingError';
  592. function navigationCancelingError(message) {
  593. var error = Error('NavigationCancelingError: ' + message);
  594. error[NAVIGATION_CANCELING_ERROR] = true;
  595. return error;
  596. }
  597. function isNavigationCancelingError(error) {
  598. return error && error[NAVIGATION_CANCELING_ERROR];
  599. }
  600. // Matches the route configuration (`route`) against the actual URL (`segments`).
  601. function defaultUrlMatcher(segments, segmentGroup, route) {
  602. var parts = route.path.split('/');
  603. if (parts.length > segments.length) {
  604. // The actual URL is shorter than the config, no match
  605. return null;
  606. }
  607. if (route.pathMatch === 'full' &&
  608. (segmentGroup.hasChildren() || parts.length < segments.length)) {
  609. // The config is longer than the actual URL but we are looking for a full match, return null
  610. return null;
  611. }
  612. var posParams = {};
  613. // Check each config part against the actual URL
  614. for (var index = 0; index < parts.length; index++) {
  615. var part = parts[index];
  616. var segment = segments[index];
  617. var isParameter = part.startsWith(':');
  618. if (isParameter) {
  619. posParams[part.substring(1)] = segment;
  620. }
  621. else if (part !== segment.path) {
  622. // The actual URL part does not match the config, no match
  623. return null;
  624. }
  625. }
  626. return { consumed: segments.slice(0, parts.length), posParams: posParams };
  627. }
  628. /**
  629. * @license
  630. * Copyright Google Inc. All Rights Reserved.
  631. *
  632. * Use of this source code is governed by an MIT-style license that can be
  633. * found in the LICENSE file at https://angular.io/license
  634. */
  635. var LoadedRouterConfig = /** @class */ (function () {
  636. function LoadedRouterConfig(routes, module) {
  637. this.routes = routes;
  638. this.module = module;
  639. }
  640. return LoadedRouterConfig;
  641. }());
  642. function validateConfig(config, parentPath) {
  643. if (parentPath === void 0) { parentPath = ''; }
  644. // forEach doesn't iterate undefined values
  645. for (var i = 0; i < config.length; i++) {
  646. var route = config[i];
  647. var fullPath = getFullPath(parentPath, route);
  648. validateNode(route, fullPath);
  649. }
  650. }
  651. function validateNode(route, fullPath) {
  652. if (!route) {
  653. throw new Error("\n Invalid configuration of route '" + fullPath + "': Encountered undefined route.\n The reason might be an extra comma.\n\n Example:\n const routes: Routes = [\n { path: '', redirectTo: '/dashboard', pathMatch: 'full' },\n { path: 'dashboard', component: DashboardComponent },, << two commas\n { path: 'detail/:id', component: HeroDetailComponent }\n ];\n ");
  654. }
  655. if (Array.isArray(route)) {
  656. throw new Error("Invalid configuration of route '" + fullPath + "': Array cannot be specified");
  657. }
  658. if (!route.component && !route.children && !route.loadChildren &&
  659. (route.outlet && route.outlet !== PRIMARY_OUTLET)) {
  660. throw new Error("Invalid configuration of route '" + fullPath + "': a componentless route without children or loadChildren cannot have a named outlet set");
  661. }
  662. if (route.redirectTo && route.children) {
  663. throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and children cannot be used together");
  664. }
  665. if (route.redirectTo && route.loadChildren) {
  666. throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and loadChildren cannot be used together");
  667. }
  668. if (route.children && route.loadChildren) {
  669. throw new Error("Invalid configuration of route '" + fullPath + "': children and loadChildren cannot be used together");
  670. }
  671. if (route.redirectTo && route.component) {
  672. throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and component cannot be used together");
  673. }
  674. if (route.path && route.matcher) {
  675. throw new Error("Invalid configuration of route '" + fullPath + "': path and matcher cannot be used together");
  676. }
  677. if (route.redirectTo === void 0 && !route.component && !route.children && !route.loadChildren) {
  678. throw new Error("Invalid configuration of route '" + fullPath + "'. One of the following must be provided: component, redirectTo, children or loadChildren");
  679. }
  680. if (route.path === void 0 && route.matcher === void 0) {
  681. throw new Error("Invalid configuration of route '" + fullPath + "': routes must have either a path or a matcher specified");
  682. }
  683. if (typeof route.path === 'string' && route.path.charAt(0) === '/') {
  684. throw new Error("Invalid configuration of route '" + fullPath + "': path cannot start with a slash");
  685. }
  686. if (route.path === '' && route.redirectTo !== void 0 && route.pathMatch === void 0) {
  687. var exp = "The default value of 'pathMatch' is 'prefix', but often the intent is to use 'full'.";
  688. throw new Error("Invalid configuration of route '{path: \"" + fullPath + "\", redirectTo: \"" + route.redirectTo + "\"}': please provide 'pathMatch'. " + exp);
  689. }
  690. if (route.pathMatch !== void 0 && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') {
  691. throw new Error("Invalid configuration of route '" + fullPath + "': pathMatch can only be set to 'prefix' or 'full'");
  692. }
  693. if (route.children) {
  694. validateConfig(route.children, fullPath);
  695. }
  696. }
  697. function getFullPath(parentPath, currentRoute) {
  698. if (!currentRoute) {
  699. return parentPath;
  700. }
  701. if (!parentPath && !currentRoute.path) {
  702. return '';
  703. }
  704. else if (parentPath && !currentRoute.path) {
  705. return parentPath + "/";
  706. }
  707. else if (!parentPath && currentRoute.path) {
  708. return currentRoute.path;
  709. }
  710. else {
  711. return parentPath + "/" + currentRoute.path;
  712. }
  713. }
  714. /**
  715. * Makes a copy of the config and adds any default required properties.
  716. */
  717. function standardizeConfig(r) {
  718. var children = r.children && r.children.map(standardizeConfig);
  719. var c = children ? __assign({}, r, { children: children }) : __assign({}, r);
  720. if (!c.component && (children || c.loadChildren) && (c.outlet && c.outlet !== PRIMARY_OUTLET)) {
  721. c.component = ɵEmptyOutletComponent;
  722. }
  723. return c;
  724. }
  725. /**
  726. * @license
  727. * Copyright Google Inc. All Rights Reserved.
  728. *
  729. * Use of this source code is governed by an MIT-style license that can be
  730. * found in the LICENSE file at https://angular.io/license
  731. */
  732. function shallowEqualArrays(a, b) {
  733. if (a.length !== b.length)
  734. return false;
  735. for (var i = 0; i < a.length; ++i) {
  736. if (!shallowEqual(a[i], b[i]))
  737. return false;
  738. }
  739. return true;
  740. }
  741. function shallowEqual(a, b) {
  742. // Casting Object.keys return values to include `undefined` as there are some cases
  743. // in IE 11 where this can happen. Cannot provide a test because the behavior only
  744. // exists in certain circumstances in IE 11, therefore doing this cast ensures the
  745. // logic is correct for when this edge case is hit.
  746. var k1 = Object.keys(a);
  747. var k2 = Object.keys(b);
  748. if (!k1 || !k2 || k1.length != k2.length) {
  749. return false;
  750. }
  751. var key;
  752. for (var i = 0; i < k1.length; i++) {
  753. key = k1[i];
  754. if (a[key] !== b[key]) {
  755. return false;
  756. }
  757. }
  758. return true;
  759. }
  760. /**
  761. * Flattens single-level nested arrays.
  762. */
  763. function flatten(arr) {
  764. return Array.prototype.concat.apply([], arr);
  765. }
  766. /**
  767. * Return the last element of an array.
  768. */
  769. function last(a) {
  770. return a.length > 0 ? a[a.length - 1] : null;
  771. }
  772. function forEach(map, callback) {
  773. for (var prop in map) {
  774. if (map.hasOwnProperty(prop)) {
  775. callback(map[prop], prop);
  776. }
  777. }
  778. }
  779. function waitForMap(obj, fn) {
  780. if (Object.keys(obj).length === 0) {
  781. return rxjs.of({});
  782. }
  783. var waitHead = [];
  784. var waitTail = [];
  785. var res = {};
  786. forEach(obj, function (a, k) {
  787. var mapped = fn(k, a).pipe(operators.map(function (r) { return res[k] = r; }));
  788. if (k === PRIMARY_OUTLET) {
  789. waitHead.push(mapped);
  790. }
  791. else {
  792. waitTail.push(mapped);
  793. }
  794. });
  795. // Closure compiler has problem with using spread operator here. So just using Array.concat.
  796. return rxjs.of.apply(null, waitHead.concat(waitTail)).pipe(operators.concatAll(), operators.last(), operators.map(function () { return res; }));
  797. }
  798. function wrapIntoObservable(value) {
  799. if (core.ɵisObservable(value)) {
  800. return value;
  801. }
  802. if (core.ɵisPromise(value)) {
  803. // Use `Promise.resolve()` to wrap promise-like instances.
  804. // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the
  805. // change detection.
  806. return rxjs.from(Promise.resolve(value));
  807. }
  808. return rxjs.of(value);
  809. }
  810. /**
  811. * @license
  812. * Copyright Google Inc. All Rights Reserved.
  813. *
  814. * Use of this source code is governed by an MIT-style license that can be
  815. * found in the LICENSE file at https://angular.io/license
  816. */
  817. function createEmptyUrlTree() {
  818. return new UrlTree(new UrlSegmentGroup([], {}), {}, null);
  819. }
  820. function containsTree(container, containee, exact) {
  821. if (exact) {
  822. return equalQueryParams(container.queryParams, containee.queryParams) &&
  823. equalSegmentGroups(container.root, containee.root);
  824. }
  825. return containsQueryParams(container.queryParams, containee.queryParams) &&
  826. containsSegmentGroup(container.root, containee.root);
  827. }
  828. function equalQueryParams(container, containee) {
  829. // TODO: This does not handle array params correctly.
  830. return shallowEqual(container, containee);
  831. }
  832. function equalSegmentGroups(container, containee) {
  833. if (!equalPath(container.segments, containee.segments))
  834. return false;
  835. if (container.numberOfChildren !== containee.numberOfChildren)
  836. return false;
  837. for (var c in containee.children) {
  838. if (!container.children[c])
  839. return false;
  840. if (!equalSegmentGroups(container.children[c], containee.children[c]))
  841. return false;
  842. }
  843. return true;
  844. }
  845. function containsQueryParams(container, containee) {
  846. // TODO: This does not handle array params correctly.
  847. return Object.keys(containee).length <= Object.keys(container).length &&
  848. Object.keys(containee).every(function (key) { return containee[key] === container[key]; });
  849. }
  850. function containsSegmentGroup(container, containee) {
  851. return containsSegmentGroupHelper(container, containee, containee.segments);
  852. }
  853. function containsSegmentGroupHelper(container, containee, containeePaths) {
  854. if (container.segments.length > containeePaths.length) {
  855. var current = container.segments.slice(0, containeePaths.length);
  856. if (!equalPath(current, containeePaths))
  857. return false;
  858. if (containee.hasChildren())
  859. return false;
  860. return true;
  861. }
  862. else if (container.segments.length === containeePaths.length) {
  863. if (!equalPath(container.segments, containeePaths))
  864. return false;
  865. for (var c in containee.children) {
  866. if (!container.children[c])
  867. return false;
  868. if (!containsSegmentGroup(container.children[c], containee.children[c]))
  869. return false;
  870. }
  871. return true;
  872. }
  873. else {
  874. var current = containeePaths.slice(0, container.segments.length);
  875. var next = containeePaths.slice(container.segments.length);
  876. if (!equalPath(container.segments, current))
  877. return false;
  878. if (!container.children[PRIMARY_OUTLET])
  879. return false;
  880. return containsSegmentGroupHelper(container.children[PRIMARY_OUTLET], containee, next);
  881. }
  882. }
  883. /**
  884. * @description
  885. *
  886. * Represents the parsed URL.
  887. *
  888. * Since a router state is a tree, and the URL is nothing but a serialized state, the URL is a
  889. * serialized tree.
  890. * UrlTree is a data structure that provides a lot of affordances in dealing with URLs
  891. *
  892. * @usageNotes
  893. * ### Example
  894. *
  895. * ```
  896. * @Component({templateUrl:'template.html'})
  897. * class MyComponent {
  898. * constructor(router: Router) {
  899. * const tree: UrlTree =
  900. * router.parseUrl('/team/33/(user/victor//support:help)?debug=true#fragment');
  901. * const f = tree.fragment; // return 'fragment'
  902. * const q = tree.queryParams; // returns {debug: 'true'}
  903. * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
  904. * const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33'
  905. * g.children[PRIMARY_OUTLET].segments; // returns 2 segments 'user' and 'victor'
  906. * g.children['support'].segments; // return 1 segment 'help'
  907. * }
  908. * }
  909. * ```
  910. *
  911. * @publicApi
  912. */
  913. var UrlTree = /** @class */ (function () {
  914. /** @internal */
  915. function UrlTree(
  916. /** The root segment group of the URL tree */
  917. root,
  918. /** The query params of the URL */
  919. queryParams,
  920. /** The fragment of the URL */
  921. fragment) {
  922. this.root = root;
  923. this.queryParams = queryParams;
  924. this.fragment = fragment;
  925. }
  926. Object.defineProperty(UrlTree.prototype, "queryParamMap", {
  927. get: function () {
  928. if (!this._queryParamMap) {
  929. this._queryParamMap = convertToParamMap(this.queryParams);
  930. }
  931. return this._queryParamMap;
  932. },
  933. enumerable: true,
  934. configurable: true
  935. });
  936. /** @docsNotRequired */
  937. UrlTree.prototype.toString = function () { return DEFAULT_SERIALIZER.serialize(this); };
  938. return UrlTree;
  939. }());
  940. /**
  941. * @description
  942. *
  943. * Represents the parsed URL segment group.
  944. *
  945. * See `UrlTree` for more information.
  946. *
  947. * @publicApi
  948. */
  949. var UrlSegmentGroup = /** @class */ (function () {
  950. function UrlSegmentGroup(
  951. /** The URL segments of this group. See `UrlSegment` for more information */
  952. segments,
  953. /** The list of children of this group */
  954. children) {
  955. var _this = this;
  956. this.segments = segments;
  957. this.children = children;
  958. /** The parent node in the url tree */
  959. this.parent = null;
  960. forEach(children, function (v, k) { return v.parent = _this; });
  961. }
  962. /** Whether the segment has child segments */
  963. UrlSegmentGroup.prototype.hasChildren = function () { return this.numberOfChildren > 0; };
  964. Object.defineProperty(UrlSegmentGroup.prototype, "numberOfChildren", {
  965. /** Number of child segments */
  966. get: function () { return Object.keys(this.children).length; },
  967. enumerable: true,
  968. configurable: true
  969. });
  970. /** @docsNotRequired */
  971. UrlSegmentGroup.prototype.toString = function () { return serializePaths(this); };
  972. return UrlSegmentGroup;
  973. }());
  974. /**
  975. * @description
  976. *
  977. * Represents a single URL segment.
  978. *
  979. * A UrlSegment is a part of a URL between the two slashes. It contains a path and the matrix
  980. * parameters associated with the segment.
  981. *
  982. * @usageNotes
  983. * ### Example
  984. *
  985. * ```
  986. * @Component({templateUrl:'template.html'})
  987. * class MyComponent {
  988. * constructor(router: Router) {
  989. * const tree: UrlTree = router.parseUrl('/team;id=33');
  990. * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
  991. * const s: UrlSegment[] = g.segments;
  992. * s[0].path; // returns 'team'
  993. * s[0].parameters; // returns {id: 33}
  994. * }
  995. * }
  996. * ```
  997. *
  998. * @publicApi
  999. */
  1000. var UrlSegment = /** @class */ (function () {
  1001. function UrlSegment(
  1002. /** The path part of a URL segment */
  1003. path,
  1004. /** The matrix parameters associated with a segment */
  1005. parameters) {
  1006. this.path = path;
  1007. this.parameters = parameters;
  1008. }
  1009. Object.defineProperty(UrlSegment.prototype, "parameterMap", {
  1010. get: function () {
  1011. if (!this._parameterMap) {
  1012. this._parameterMap = convertToParamMap(this.parameters);
  1013. }
  1014. return this._parameterMap;
  1015. },
  1016. enumerable: true,
  1017. configurable: true
  1018. });
  1019. /** @docsNotRequired */
  1020. UrlSegment.prototype.toString = function () { return serializePath(this); };
  1021. return UrlSegment;
  1022. }());
  1023. function equalSegments(as, bs) {
  1024. return equalPath(as, bs) && as.every(function (a, i) { return shallowEqual(a.parameters, bs[i].parameters); });
  1025. }
  1026. function equalPath(as, bs) {
  1027. if (as.length !== bs.length)
  1028. return false;
  1029. return as.every(function (a, i) { return a.path === bs[i].path; });
  1030. }
  1031. function mapChildrenIntoArray(segment, fn) {
  1032. var res = [];
  1033. forEach(segment.children, function (child, childOutlet) {
  1034. if (childOutlet === PRIMARY_OUTLET) {
  1035. res = res.concat(fn(child, childOutlet));
  1036. }
  1037. });
  1038. forEach(segment.children, function (child, childOutlet) {
  1039. if (childOutlet !== PRIMARY_OUTLET) {
  1040. res = res.concat(fn(child, childOutlet));
  1041. }
  1042. });
  1043. return res;
  1044. }
  1045. /**
  1046. * @description
  1047. *
  1048. * Serializes and deserializes a URL string into a URL tree.
  1049. *
  1050. * The url serialization strategy is customizable. You can
  1051. * make all URLs case insensitive by providing a custom UrlSerializer.
  1052. *
  1053. * See `DefaultUrlSerializer` for an example of a URL serializer.
  1054. *
  1055. * @publicApi
  1056. */
  1057. var UrlSerializer = /** @class */ (function () {
  1058. function UrlSerializer() {
  1059. }
  1060. return UrlSerializer;
  1061. }());
  1062. /**
  1063. * @description
  1064. *
  1065. * A default implementation of the `UrlSerializer`.
  1066. *
  1067. * Example URLs:
  1068. *
  1069. * ```
  1070. * /inbox/33(popup:compose)
  1071. * /inbox/33;open=true/messages/44
  1072. * ```
  1073. *
  1074. * DefaultUrlSerializer uses parentheses to serialize secondary segments (e.g., popup:compose), the
  1075. * colon syntax to specify the outlet, and the ';parameter=value' syntax (e.g., open=true) to
  1076. * specify route specific parameters.
  1077. *
  1078. * @publicApi
  1079. */
  1080. var DefaultUrlSerializer = /** @class */ (function () {
  1081. function DefaultUrlSerializer() {
  1082. }
  1083. /** Parses a url into a `UrlTree` */
  1084. DefaultUrlSerializer.prototype.parse = function (url) {
  1085. var p = new UrlParser(url);
  1086. return new UrlTree(p.parseRootSegment(), p.parseQueryParams(), p.parseFragment());
  1087. };
  1088. /** Converts a `UrlTree` into a url */
  1089. DefaultUrlSerializer.prototype.serialize = function (tree) {
  1090. var segment = "/" + serializeSegment(tree.root, true);
  1091. var query = serializeQueryParams(tree.queryParams);
  1092. var fragment = typeof tree.fragment === "string" ? "#" + encodeUriFragment(tree.fragment) : '';
  1093. return "" + segment + query + fragment;
  1094. };
  1095. return DefaultUrlSerializer;
  1096. }());
  1097. var DEFAULT_SERIALIZER = new DefaultUrlSerializer();
  1098. function serializePaths(segment) {
  1099. return segment.segments.map(function (p) { return serializePath(p); }).join('/');
  1100. }
  1101. function serializeSegment(segment, root) {
  1102. if (!segment.hasChildren()) {
  1103. return serializePaths(segment);
  1104. }
  1105. if (root) {
  1106. var primary = segment.children[PRIMARY_OUTLET] ?
  1107. serializeSegment(segment.children[PRIMARY_OUTLET], false) :
  1108. '';
  1109. var children_1 = [];
  1110. forEach(segment.children, function (v, k) {
  1111. if (k !== PRIMARY_OUTLET) {
  1112. children_1.push(k + ":" + serializeSegment(v, false));
  1113. }
  1114. });
  1115. return children_1.length > 0 ? primary + "(" + children_1.join('//') + ")" : primary;
  1116. }
  1117. else {
  1118. var children = mapChildrenIntoArray(segment, function (v, k) {
  1119. if (k === PRIMARY_OUTLET) {
  1120. return [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
  1121. }
  1122. return [k + ":" + serializeSegment(v, false)];
  1123. });
  1124. return serializePaths(segment) + "/(" + children.join('//') + ")";
  1125. }
  1126. }
  1127. /**
  1128. * Encodes a URI string with the default encoding. This function will only ever be called from
  1129. * `encodeUriQuery` or `encodeUriSegment` as it's the base set of encodings to be used. We need
  1130. * a custom encoding because encodeURIComponent is too aggressive and encodes stuff that doesn't
  1131. * have to be encoded per https://url.spec.whatwg.org.
  1132. */
  1133. function encodeUriString(s) {
  1134. return encodeURIComponent(s)
  1135. .replace(/%40/g, '@')
  1136. .replace(/%3A/gi, ':')
  1137. .replace(/%24/g, '$')
  1138. .replace(/%2C/gi, ',');
  1139. }
  1140. /**
  1141. * This function should be used to encode both keys and values in a query string key/value. In
  1142. * the following URL, you need to call encodeUriQuery on "k" and "v":
  1143. *
  1144. * http://www.site.org/html;mk=mv?k=v#f
  1145. */
  1146. function encodeUriQuery(s) {
  1147. return encodeUriString(s).replace(/%3B/gi, ';');
  1148. }
  1149. /**
  1150. * This function should be used to encode a URL fragment. In the following URL, you need to call
  1151. * encodeUriFragment on "f":
  1152. *
  1153. * http://www.site.org/html;mk=mv?k=v#f
  1154. */
  1155. function encodeUriFragment(s) {
  1156. return encodeURI(s);
  1157. }
  1158. /**
  1159. * This function should be run on any URI segment as well as the key and value in a key/value
  1160. * pair for matrix params. In the following URL, you need to call encodeUriSegment on "html",
  1161. * "mk", and "mv":
  1162. *
  1163. * http://www.site.org/html;mk=mv?k=v#f
  1164. */
  1165. function encodeUriSegment(s) {
  1166. return encodeUriString(s).replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/%26/gi, '&');
  1167. }
  1168. function decode(s) {
  1169. return decodeURIComponent(s);
  1170. }
  1171. // Query keys/values should have the "+" replaced first, as "+" in a query string is " ".
  1172. // decodeURIComponent function will not decode "+" as a space.
  1173. function decodeQuery(s) {
  1174. return decode(s.replace(/\+/g, '%20'));
  1175. }
  1176. function serializePath(path) {
  1177. return "" + encodeUriSegment(path.path) + serializeMatrixParams(path.parameters);
  1178. }
  1179. function serializeMatrixParams(params) {
  1180. return Object.keys(params)
  1181. .map(function (key) { return ";" + encodeUriSegment(key) + "=" + encodeUriSegment(params[key]); })
  1182. .join('');
  1183. }
  1184. function serializeQueryParams(params) {
  1185. var strParams = Object.keys(params).map(function (name) {
  1186. var value = params[name];
  1187. return Array.isArray(value) ?
  1188. value.map(function (v) { return encodeUriQuery(name) + "=" + encodeUriQuery(v); }).join('&') :
  1189. encodeUriQuery(name) + "=" + encodeUriQuery(value);
  1190. });
  1191. return strParams.length ? "?" + strParams.join("&") : '';
  1192. }
  1193. var SEGMENT_RE = /^[^\/()?;=#]+/;
  1194. function matchSegments(str) {
  1195. var match = str.match(SEGMENT_RE);
  1196. return match ? match[0] : '';
  1197. }
  1198. var QUERY_PARAM_RE = /^[^=?&#]+/;
  1199. // Return the name of the query param at the start of the string or an empty string
  1200. function matchQueryParams(str) {
  1201. var match = str.match(QUERY_PARAM_RE);
  1202. return match ? match[0] : '';
  1203. }
  1204. var QUERY_PARAM_VALUE_RE = /^[^?&#]+/;
  1205. // Return the value of the query param at the start of the string or an empty string
  1206. function matchUrlQueryParamValue(str) {
  1207. var match = str.match(QUERY_PARAM_VALUE_RE);
  1208. return match ? match[0] : '';
  1209. }
  1210. var UrlParser = /** @class */ (function () {
  1211. function UrlParser(url) {
  1212. this.url = url;
  1213. this.remaining = url;
  1214. }
  1215. UrlParser.prototype.parseRootSegment = function () {
  1216. this.consumeOptional('/');
  1217. if (this.remaining === '' || this.peekStartsWith('?') || this.peekStartsWith('#')) {
  1218. return new UrlSegmentGroup([], {});
  1219. }
  1220. // The root segment group never has segments
  1221. return new UrlSegmentGroup([], this.parseChildren());
  1222. };
  1223. UrlParser.prototype.parseQueryParams = function () {
  1224. var params = {};
  1225. if (this.consumeOptional('?')) {
  1226. do {
  1227. this.parseQueryParam(params);
  1228. } while (this.consumeOptional('&'));
  1229. }
  1230. return params;
  1231. };
  1232. UrlParser.prototype.parseFragment = function () {
  1233. return this.consumeOptional('#') ? decodeURIComponent(this.remaining) : null;
  1234. };
  1235. UrlParser.prototype.parseChildren = function () {
  1236. if (this.remaining === '') {
  1237. return {};
  1238. }
  1239. this.consumeOptional('/');
  1240. var segments = [];
  1241. if (!this.peekStartsWith('(')) {
  1242. segments.push(this.parseSegment());
  1243. }
  1244. while (this.peekStartsWith('/') && !this.peekStartsWith('//') && !this.peekStartsWith('/(')) {
  1245. this.capture('/');
  1246. segments.push(this.parseSegment());
  1247. }
  1248. var children = {};
  1249. if (this.peekStartsWith('/(')) {
  1250. this.capture('/');
  1251. children = this.parseParens(true);
  1252. }
  1253. var res = {};
  1254. if (this.peekStartsWith('(')) {
  1255. res = this.parseParens(false);
  1256. }
  1257. if (segments.length > 0 || Object.keys(children).length > 0) {
  1258. res[PRIMARY_OUTLET] = new UrlSegmentGroup(segments, children);
  1259. }
  1260. return res;
  1261. };
  1262. // parse a segment with its matrix parameters
  1263. // ie `name;k1=v1;k2`
  1264. UrlParser.prototype.parseSegment = function () {
  1265. var path = matchSegments(this.remaining);
  1266. if (path === '' && this.peekStartsWith(';')) {
  1267. throw new Error("Empty path url segment cannot have parameters: '" + this.remaining + "'.");
  1268. }
  1269. this.capture(path);
  1270. return new UrlSegment(decode(path), this.parseMatrixParams());
  1271. };
  1272. UrlParser.prototype.parseMatrixParams = function () {
  1273. var params = {};
  1274. while (this.consumeOptional(';')) {
  1275. this.parseParam(params);
  1276. }
  1277. return params;
  1278. };
  1279. UrlParser.prototype.parseParam = function (params) {
  1280. var key = matchSegments(this.remaining);
  1281. if (!key) {
  1282. return;
  1283. }
  1284. this.capture(key);
  1285. var value = '';
  1286. if (this.consumeOptional('=')) {
  1287. var valueMatch = matchSegments(this.remaining);
  1288. if (valueMatch) {
  1289. value = valueMatch;
  1290. this.capture(value);
  1291. }
  1292. }
  1293. params[decode(key)] = decode(value);
  1294. };
  1295. // Parse a single query parameter `name[=value]`
  1296. UrlParser.prototype.parseQueryParam = function (params) {
  1297. var key = matchQueryParams(this.remaining);
  1298. if (!key) {
  1299. return;
  1300. }
  1301. this.capture(key);
  1302. var value = '';
  1303. if (this.consumeOptional('=')) {
  1304. var valueMatch = matchUrlQueryParamValue(this.remaining);
  1305. if (valueMatch) {
  1306. value = valueMatch;
  1307. this.capture(value);
  1308. }
  1309. }
  1310. var decodedKey = decodeQuery(key);
  1311. var decodedVal = decodeQuery(value);
  1312. if (params.hasOwnProperty(decodedKey)) {
  1313. // Append to existing values
  1314. var currentVal = params[decodedKey];
  1315. if (!Array.isArray(currentVal)) {
  1316. currentVal = [currentVal];
  1317. params[decodedKey] = currentVal;
  1318. }
  1319. currentVal.push(decodedVal);
  1320. }
  1321. else {
  1322. // Create a new value
  1323. params[decodedKey] = decodedVal;
  1324. }
  1325. };
  1326. // parse `(a/b//outlet_name:c/d)`
  1327. UrlParser.prototype.parseParens = function (allowPrimary) {
  1328. var segments = {};
  1329. this.capture('(');
  1330. while (!this.consumeOptional(')') && this.remaining.length > 0) {
  1331. var path = matchSegments(this.remaining);
  1332. var next = this.remaining[path.length];
  1333. // if is is not one of these characters, then the segment was unescaped
  1334. // or the group was not closed
  1335. if (next !== '/' && next !== ')' && next !== ';') {
  1336. throw new Error("Cannot parse url '" + this.url + "'");
  1337. }
  1338. var outletName = undefined;
  1339. if (path.indexOf(':') > -1) {
  1340. outletName = path.substr(0, path.indexOf(':'));
  1341. this.capture(outletName);
  1342. this.capture(':');
  1343. }
  1344. else if (allowPrimary) {
  1345. outletName = PRIMARY_OUTLET;
  1346. }
  1347. var children = this.parseChildren();
  1348. segments[outletName] = Object.keys(children).length === 1 ? children[PRIMARY_OUTLET] :
  1349. new UrlSegmentGroup([], children);
  1350. this.consumeOptional('//');
  1351. }
  1352. return segments;
  1353. };
  1354. UrlParser.prototype.peekStartsWith = function (str) { return this.remaining.startsWith(str); };
  1355. // Consumes the prefix when it is present and returns whether it has been consumed
  1356. UrlParser.prototype.consumeOptional = function (str) {
  1357. if (this.peekStartsWith(str)) {
  1358. this.remaining = this.remaining.substring(str.length);
  1359. return true;
  1360. }
  1361. return false;
  1362. };
  1363. UrlParser.prototype.capture = function (str) {
  1364. if (!this.consumeOptional(str)) {
  1365. throw new Error("Expected \"" + str + "\".");
  1366. }
  1367. };
  1368. return UrlParser;
  1369. }());
  1370. /**
  1371. * @license
  1372. * Copyright Google Inc. All Rights Reserved.
  1373. *
  1374. * Use of this source code is governed by an MIT-style license that can be
  1375. * found in the LICENSE file at https://angular.io/license
  1376. */
  1377. var Tree = /** @class */ (function () {
  1378. function Tree(root) {
  1379. this._root = root;
  1380. }
  1381. Object.defineProperty(Tree.prototype, "root", {
  1382. get: function () { return this._root.value; },
  1383. enumerable: true,
  1384. configurable: true
  1385. });
  1386. /**
  1387. * @internal
  1388. */
  1389. Tree.prototype.parent = function (t) {
  1390. var p = this.pathFromRoot(t);
  1391. return p.length > 1 ? p[p.length - 2] : null;
  1392. };
  1393. /**
  1394. * @internal
  1395. */
  1396. Tree.prototype.children = function (t) {
  1397. var n = findNode(t, this._root);
  1398. return n ? n.children.map(function (t) { return t.value; }) : [];
  1399. };
  1400. /**
  1401. * @internal
  1402. */
  1403. Tree.prototype.firstChild = function (t) {
  1404. var n = findNode(t, this._root);
  1405. return n && n.children.length > 0 ? n.children[0].value : null;
  1406. };
  1407. /**
  1408. * @internal
  1409. */
  1410. Tree.prototype.siblings = function (t) {
  1411. var p = findPath(t, this._root);
  1412. if (p.length < 2)
  1413. return [];
  1414. var c = p[p.length - 2].children.map(function (c) { return c.value; });
  1415. return c.filter(function (cc) { return cc !== t; });
  1416. };
  1417. /**
  1418. * @internal
  1419. */
  1420. Tree.prototype.pathFromRoot = function (t) { return findPath(t, this._root).map(function (s) { return s.value; }); };
  1421. return Tree;
  1422. }());
  1423. // DFS for the node matching the value
  1424. function findNode(value, node) {
  1425. var e_1, _a;
  1426. if (value === node.value)
  1427. return node;
  1428. try {
  1429. for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
  1430. var child = _c.value;
  1431. var node_1 = findNode(value, child);
  1432. if (node_1)
  1433. return node_1;
  1434. }
  1435. }
  1436. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1437. finally {
  1438. try {
  1439. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1440. }
  1441. finally { if (e_1) throw e_1.error; }
  1442. }
  1443. return null;
  1444. }
  1445. // Return the path to the node with the given value using DFS
  1446. function findPath(value, node) {
  1447. var e_2, _a;
  1448. if (value === node.value)
  1449. return [node];
  1450. try {
  1451. for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
  1452. var child = _c.value;
  1453. var path = findPath(value, child);
  1454. if (path.length) {
  1455. path.unshift(node);
  1456. return path;
  1457. }
  1458. }
  1459. }
  1460. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  1461. finally {
  1462. try {
  1463. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1464. }
  1465. finally { if (e_2) throw e_2.error; }
  1466. }
  1467. return [];
  1468. }
  1469. var TreeNode = /** @class */ (function () {
  1470. function TreeNode(value, children) {
  1471. this.value = value;
  1472. this.children = children;
  1473. }
  1474. TreeNode.prototype.toString = function () { return "TreeNode(" + this.value + ")"; };
  1475. return TreeNode;
  1476. }());
  1477. // Return the list of T indexed by outlet name
  1478. function nodeChildrenAsMap(node) {
  1479. var map = {};
  1480. if (node) {
  1481. node.children.forEach(function (child) { return map[child.value.outlet] = child; });
  1482. }
  1483. return map;
  1484. }
  1485. /**
  1486. * @license
  1487. * Copyright Google Inc. All Rights Reserved.
  1488. *
  1489. * Use of this source code is governed by an MIT-style license that can be
  1490. * found in the LICENSE file at https://angular.io/license
  1491. */
  1492. /**
  1493. * @description
  1494. *
  1495. * Represents the state of the router.
  1496. *
  1497. * RouterState is a tree of activated routes. Every node in this tree knows about the "consumed" URL
  1498. * segments, the extracted parameters, and the resolved data.
  1499. *
  1500. * @usageNotes
  1501. * ### Example
  1502. *
  1503. * ```
  1504. * @Component({templateUrl:'template.html'})
  1505. * class MyComponent {
  1506. * constructor(router: Router) {
  1507. * const state: RouterState = router.routerState;
  1508. * const root: ActivatedRoute = state.root;
  1509. * const child = root.firstChild;
  1510. * const id: Observable<string> = child.params.map(p => p.id);
  1511. * //...
  1512. * }
  1513. * }
  1514. * ```
  1515. *
  1516. * See `ActivatedRoute` for more information.
  1517. *
  1518. * @publicApi
  1519. */
  1520. var RouterState = /** @class */ (function (_super) {
  1521. __extends(RouterState, _super);
  1522. /** @internal */
  1523. function RouterState(root,
  1524. /** The current snapshot of the router state */
  1525. snapshot) {
  1526. var _this = _super.call(this, root) || this;
  1527. _this.snapshot = snapshot;
  1528. setRouterState(_this, root);
  1529. return _this;
  1530. }
  1531. RouterState.prototype.toString = function () { return this.snapshot.toString(); };
  1532. return RouterState;
  1533. }(Tree));
  1534. function createEmptyState(urlTree, rootComponent) {
  1535. var snapshot = createEmptyStateSnapshot(urlTree, rootComponent);
  1536. var emptyUrl = new rxjs.BehaviorSubject([new UrlSegment('', {})]);
  1537. var emptyParams = new rxjs.BehaviorSubject({});
  1538. var emptyData = new rxjs.BehaviorSubject({});
  1539. var emptyQueryParams = new rxjs.BehaviorSubject({});
  1540. var fragment = new rxjs.BehaviorSubject('');
  1541. var activated = new ActivatedRoute(emptyUrl, emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, snapshot.root);
  1542. activated.snapshot = snapshot.root;
  1543. return new RouterState(new TreeNode(activated, []), snapshot);
  1544. }
  1545. function createEmptyStateSnapshot(urlTree, rootComponent) {
  1546. var emptyParams = {};
  1547. var emptyData = {};
  1548. var emptyQueryParams = {};
  1549. var fragment = '';
  1550. var activated = new ActivatedRouteSnapshot([], emptyParams, emptyQueryParams, fragment, emptyData, PRIMARY_OUTLET, rootComponent, null, urlTree.root, -1, {});
  1551. return new RouterStateSnapshot('', new TreeNode(activated, []));
  1552. }
  1553. /**
  1554. * @description
  1555. *
  1556. * Contains the information about a route associated with a component loaded in an
  1557. * outlet. An `ActivatedRoute` can also be used to traverse the router state tree.
  1558. *
  1559. * {@example router/activated-route/module.ts region="activated-route"
  1560. * header="activated-route.component.ts" linenums="false"}
  1561. *
  1562. * @publicApi
  1563. */
  1564. var ActivatedRoute = /** @class */ (function () {
  1565. /** @internal */
  1566. function ActivatedRoute(
  1567. /** An observable of the URL segments matched by this route */
  1568. url,
  1569. /** An observable of the matrix parameters scoped to this route */
  1570. params,
  1571. /** An observable of the query parameters shared by all the routes */
  1572. queryParams,
  1573. /** An observable of the URL fragment shared by all the routes */
  1574. fragment,
  1575. /** An observable of the static and resolved data of this route. */
  1576. data,
  1577. /** The outlet name of the route. It's a constant */
  1578. outlet,
  1579. /** The component of the route. It's a constant */
  1580. // TODO(vsavkin): remove |string
  1581. component, futureSnapshot) {
  1582. this.url = url;
  1583. this.params = params;
  1584. this.queryParams = queryParams;
  1585. this.fragment = fragment;
  1586. this.data = data;
  1587. this.outlet = outlet;
  1588. this.component = component;
  1589. this._futureSnapshot = futureSnapshot;
  1590. }
  1591. Object.defineProperty(ActivatedRoute.prototype, "routeConfig", {
  1592. /** The configuration used to match this route */
  1593. get: function () { return this._futureSnapshot.routeConfig; },
  1594. enumerable: true,
  1595. configurable: true
  1596. });
  1597. Object.defineProperty(ActivatedRoute.prototype, "root", {
  1598. /** The root of the router state */
  1599. get: function () { return this._routerState.root; },
  1600. enumerable: true,
  1601. configurable: true
  1602. });
  1603. Object.defineProperty(ActivatedRoute.prototype, "parent", {
  1604. /** The parent of this route in the router state tree */
  1605. get: function () { return this._routerState.parent(this); },
  1606. enumerable: true,
  1607. configurable: true
  1608. });
  1609. Object.defineProperty(ActivatedRoute.prototype, "firstChild", {
  1610. /** The first child of this route in the router state tree */
  1611. get: function () { return this._routerState.firstChild(this); },
  1612. enumerable: true,
  1613. configurable: true
  1614. });
  1615. Object.defineProperty(ActivatedRoute.prototype, "children", {
  1616. /** The children of this route in the router state tree */
  1617. get: function () { return this._routerState.children(this); },
  1618. enumerable: true,
  1619. configurable: true
  1620. });
  1621. Object.defineProperty(ActivatedRoute.prototype, "pathFromRoot", {
  1622. /** The path from the root of the router state tree to this route */
  1623. get: function () { return this._routerState.pathFromRoot(this); },
  1624. enumerable: true,
  1625. configurable: true
  1626. });
  1627. Object.defineProperty(ActivatedRoute.prototype, "paramMap", {
  1628. get: function () {
  1629. if (!this._paramMap) {
  1630. this._paramMap = this.params.pipe(operators.map(function (p) { return convertToParamMap(p); }));
  1631. }
  1632. return this._paramMap;
  1633. },
  1634. enumerable: true,
  1635. configurable: true
  1636. });
  1637. Object.defineProperty(ActivatedRoute.prototype, "queryParamMap", {
  1638. get: function () {
  1639. if (!this._queryParamMap) {
  1640. this._queryParamMap =
  1641. this.queryParams.pipe(operators.map(function (p) { return convertToParamMap(p); }));
  1642. }
  1643. return this._queryParamMap;
  1644. },
  1645. enumerable: true,
  1646. configurable: true
  1647. });
  1648. ActivatedRoute.prototype.toString = function () {
  1649. return this.snapshot ? this.snapshot.toString() : "Future(" + this._futureSnapshot + ")";
  1650. };
  1651. return ActivatedRoute;
  1652. }());
  1653. /**
  1654. * Returns the inherited params, data, and resolve for a given route.
  1655. * By default, this only inherits values up to the nearest path-less or component-less route.
  1656. * @internal
  1657. */
  1658. function inheritedParamsDataResolve(route, paramsInheritanceStrategy) {
  1659. if (paramsInheritanceStrategy === void 0) { paramsInheritanceStrategy = 'emptyOnly'; }
  1660. var pathFromRoot = route.pathFromRoot;
  1661. var inheritingStartingFrom = 0;
  1662. if (paramsInheritanceStrategy !== 'always') {
  1663. inheritingStartingFrom = pathFromRoot.length - 1;
  1664. while (inheritingStartingFrom >= 1) {
  1665. var current = pathFromRoot[inheritingStartingFrom];
  1666. var parent_1 = pathFromRoot[inheritingStartingFrom - 1];
  1667. // current route is an empty path => inherits its parent's params and data
  1668. if (current.routeConfig && current.routeConfig.path === '') {
  1669. inheritingStartingFrom--;
  1670. // parent is componentless => current route should inherit its params and data
  1671. }
  1672. else if (!parent_1.component) {
  1673. inheritingStartingFrom--;
  1674. }
  1675. else {
  1676. break;
  1677. }
  1678. }
  1679. }
  1680. return flattenInherited(pathFromRoot.slice(inheritingStartingFrom));
  1681. }
  1682. /** @internal */
  1683. function flattenInherited(pathFromRoot) {
  1684. return pathFromRoot.reduce(function (res, curr) {
  1685. var params = __assign({}, res.params, curr.params);
  1686. var data = __assign({}, res.data, curr.data);
  1687. var resolve = __assign({}, res.resolve, curr._resolvedData);
  1688. return { params: params, data: data, resolve: resolve };
  1689. }, { params: {}, data: {}, resolve: {} });
  1690. }
  1691. /**
  1692. * @description
  1693. *
  1694. * Contains the information about a route associated with a component loaded in an
  1695. * outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to
  1696. * traverse the router state tree.
  1697. *
  1698. * ```
  1699. * @Component({templateUrl:'./my-component.html'})
  1700. * class MyComponent {
  1701. * constructor(route: ActivatedRoute) {
  1702. * const id: string = route.snapshot.params.id;
  1703. * const url: string = route.snapshot.url.join('');
  1704. * const user = route.snapshot.data.user;
  1705. * }
  1706. * }
  1707. * ```
  1708. *
  1709. * @publicApi
  1710. */
  1711. var ActivatedRouteSnapshot = /** @class */ (function () {
  1712. /** @internal */
  1713. function ActivatedRouteSnapshot(
  1714. /** The URL segments matched by this route */
  1715. url,
  1716. /** The matrix parameters scoped to this route */
  1717. params,
  1718. /** The query parameters shared by all the routes */
  1719. queryParams,
  1720. /** The URL fragment shared by all the routes */
  1721. fragment,
  1722. /** The static and resolved data of this route */
  1723. data,
  1724. /** The outlet name of the route */
  1725. outlet,
  1726. /** The component of the route */
  1727. component, routeConfig, urlSegment, lastPathIndex, resolve) {
  1728. this.url = url;
  1729. this.params = params;
  1730. this.queryParams = queryParams;
  1731. this.fragment = fragment;
  1732. this.data = data;
  1733. this.outlet = outlet;
  1734. this.component = component;
  1735. this.routeConfig = routeConfig;
  1736. this._urlSegment = urlSegment;
  1737. this._lastPathIndex = lastPathIndex;
  1738. this._resolve = resolve;
  1739. }
  1740. Object.defineProperty(ActivatedRouteSnapshot.prototype, "root", {
  1741. /** The root of the router state */
  1742. get: function () { return this._routerState.root; },
  1743. enumerable: true,
  1744. configurable: true
  1745. });
  1746. Object.defineProperty(ActivatedRouteSnapshot.prototype, "parent", {
  1747. /** The parent of this route in the router state tree */
  1748. get: function () { return this._routerState.parent(this); },
  1749. enumerable: true,
  1750. configurable: true
  1751. });
  1752. Object.defineProperty(ActivatedRouteSnapshot.prototype, "firstChild", {
  1753. /** The first child of this route in the router state tree */
  1754. get: function () { return this._routerState.firstChild(this); },
  1755. enumerable: true,
  1756. configurable: true
  1757. });
  1758. Object.defineProperty(ActivatedRouteSnapshot.prototype, "children", {
  1759. /** The children of this route in the router state tree */
  1760. get: function () { return this._routerState.children(this); },
  1761. enumerable: true,
  1762. configurable: true
  1763. });
  1764. Object.defineProperty(ActivatedRouteSnapshot.prototype, "pathFromRoot", {
  1765. /** The path from the root of the router state tree to this route */
  1766. get: function () { return this._routerState.pathFromRoot(this); },
  1767. enumerable: true,
  1768. configurable: true
  1769. });
  1770. Object.defineProperty(ActivatedRouteSnapshot.prototype, "paramMap", {
  1771. get: function () {
  1772. if (!this._paramMap) {
  1773. this._paramMap = convertToParamMap(this.params);
  1774. }
  1775. return this._paramMap;
  1776. },
  1777. enumerable: true,
  1778. configurable: true
  1779. });
  1780. Object.defineProperty(ActivatedRouteSnapshot.prototype, "queryParamMap", {
  1781. get: function () {
  1782. if (!this._queryParamMap) {
  1783. this._queryParamMap = convertToParamMap(this.queryParams);
  1784. }
  1785. return this._queryParamMap;
  1786. },
  1787. enumerable: true,
  1788. configurable: true
  1789. });
  1790. ActivatedRouteSnapshot.prototype.toString = function () {
  1791. var url = this.url.map(function (segment) { return segment.toString(); }).join('/');
  1792. var matched = this.routeConfig ? this.routeConfig.path : '';
  1793. return "Route(url:'" + url + "', path:'" + matched + "')";
  1794. };
  1795. return ActivatedRouteSnapshot;
  1796. }());
  1797. /**
  1798. * @description
  1799. *
  1800. * Represents the state of the router at a moment in time.
  1801. *
  1802. * This is a tree of activated route snapshots. Every node in this tree knows about
  1803. * the "consumed" URL segments, the extracted parameters, and the resolved data.
  1804. *
  1805. * @usageNotes
  1806. * ### Example
  1807. *
  1808. * ```
  1809. * @Component({templateUrl:'template.html'})
  1810. * class MyComponent {
  1811. * constructor(router: Router) {
  1812. * const state: RouterState = router.routerState;
  1813. * const snapshot: RouterStateSnapshot = state.snapshot;
  1814. * const root: ActivatedRouteSnapshot = snapshot.root;
  1815. * const child = root.firstChild;
  1816. * const id: Observable<string> = child.params.map(p => p.id);
  1817. * //...
  1818. * }
  1819. * }
  1820. * ```
  1821. *
  1822. * @publicApi
  1823. */
  1824. var RouterStateSnapshot = /** @class */ (function (_super) {
  1825. __extends(RouterStateSnapshot, _super);
  1826. /** @internal */
  1827. function RouterStateSnapshot(
  1828. /** The url from which this snapshot was created */
  1829. url, root) {
  1830. var _this = _super.call(this, root) || this;
  1831. _this.url = url;
  1832. setRouterState(_this, root);
  1833. return _this;
  1834. }
  1835. RouterStateSnapshot.prototype.toString = function () { return serializeNode(this._root); };
  1836. return RouterStateSnapshot;
  1837. }(Tree));
  1838. function setRouterState(state, node) {
  1839. node.value._routerState = state;
  1840. node.children.forEach(function (c) { return setRouterState(state, c); });
  1841. }
  1842. function serializeNode(node) {
  1843. var c = node.children.length > 0 ? " { " + node.children.map(serializeNode).join(', ') + " } " : '';
  1844. return "" + node.value + c;
  1845. }
  1846. /**
  1847. * The expectation is that the activate route is created with the right set of parameters.
  1848. * So we push new values into the observables only when they are not the initial values.
  1849. * And we detect that by checking if the snapshot field is set.
  1850. */
  1851. function advanceActivatedRoute(route) {
  1852. if (route.snapshot) {
  1853. var currentSnapshot = route.snapshot;
  1854. var nextSnapshot = route._futureSnapshot;
  1855. route.snapshot = nextSnapshot;
  1856. if (!shallowEqual(currentSnapshot.queryParams, nextSnapshot.queryParams)) {
  1857. route.queryParams.next(nextSnapshot.queryParams);
  1858. }
  1859. if (currentSnapshot.fragment !== nextSnapshot.fragment) {
  1860. route.fragment.next(nextSnapshot.fragment);
  1861. }
  1862. if (!shallowEqual(currentSnapshot.params, nextSnapshot.params)) {
  1863. route.params.next(nextSnapshot.params);
  1864. }
  1865. if (!shallowEqualArrays(currentSnapshot.url, nextSnapshot.url)) {
  1866. route.url.next(nextSnapshot.url);
  1867. }
  1868. if (!shallowEqual(currentSnapshot.data, nextSnapshot.data)) {
  1869. route.data.next(nextSnapshot.data);
  1870. }
  1871. }
  1872. else {
  1873. route.snapshot = route._futureSnapshot;
  1874. // this is for resolved data
  1875. route.data.next(route._futureSnapshot.data);
  1876. }
  1877. }
  1878. function equalParamsAndUrlSegments(a, b) {
  1879. var equalUrlParams = shallowEqual(a.params, b.params) && equalSegments(a.url, b.url);
  1880. var parentsMismatch = !a.parent !== !b.parent;
  1881. return equalUrlParams && !parentsMismatch &&
  1882. (!a.parent || equalParamsAndUrlSegments(a.parent, b.parent));
  1883. }
  1884. /**
  1885. * @license
  1886. * Copyright Google Inc. All Rights Reserved.
  1887. *
  1888. * Use of this source code is governed by an MIT-style license that can be
  1889. * found in the LICENSE file at https://angular.io/license
  1890. */
  1891. function createRouterState(routeReuseStrategy, curr, prevState) {
  1892. var root = createNode(routeReuseStrategy, curr._root, prevState ? prevState._root : undefined);
  1893. return new RouterState(root, curr);
  1894. }
  1895. function createNode(routeReuseStrategy, curr, prevState) {
  1896. // reuse an activated route that is currently displayed on the screen
  1897. if (prevState && routeReuseStrategy.shouldReuseRoute(curr.value, prevState.value.snapshot)) {
  1898. var value = prevState.value;
  1899. value._futureSnapshot = curr.value;
  1900. var children = createOrReuseChildren(routeReuseStrategy, curr, prevState);
  1901. return new TreeNode(value, children);
  1902. // retrieve an activated route that is used to be displayed, but is not currently displayed
  1903. }
  1904. else {
  1905. var detachedRouteHandle = routeReuseStrategy.retrieve(curr.value);
  1906. if (detachedRouteHandle) {
  1907. var tree = detachedRouteHandle.route;
  1908. setFutureSnapshotsOfActivatedRoutes(curr, tree);
  1909. return tree;
  1910. }
  1911. else {
  1912. var value = createActivatedRoute(curr.value);
  1913. var children = curr.children.map(function (c) { return createNode(routeReuseStrategy, c); });
  1914. return new TreeNode(value, children);
  1915. }
  1916. }
  1917. }
  1918. function setFutureSnapshotsOfActivatedRoutes(curr, result) {
  1919. if (curr.value.routeConfig !== result.value.routeConfig) {
  1920. throw new Error('Cannot reattach ActivatedRouteSnapshot created from a different route');
  1921. }
  1922. if (curr.children.length !== result.children.length) {
  1923. throw new Error('Cannot reattach ActivatedRouteSnapshot with a different number of children');
  1924. }
  1925. result.value._futureSnapshot = curr.value;
  1926. for (var i = 0; i < curr.children.length; ++i) {
  1927. setFutureSnapshotsOfActivatedRoutes(curr.children[i], result.children[i]);
  1928. }
  1929. }
  1930. function createOrReuseChildren(routeReuseStrategy, curr, prevState) {
  1931. return curr.children.map(function (child) {
  1932. var e_1, _a;
  1933. try {
  1934. for (var _b = __values(prevState.children), _c = _b.next(); !_c.done; _c = _b.next()) {
  1935. var p = _c.value;
  1936. if (routeReuseStrategy.shouldReuseRoute(p.value.snapshot, child.value)) {
  1937. return createNode(routeReuseStrategy, child, p);
  1938. }
  1939. }
  1940. }
  1941. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1942. finally {
  1943. try {
  1944. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1945. }
  1946. finally { if (e_1) throw e_1.error; }
  1947. }
  1948. return createNode(routeReuseStrategy, child);
  1949. });
  1950. }
  1951. function createActivatedRoute(c) {
  1952. return new ActivatedRoute(new rxjs.BehaviorSubject(c.url), new rxjs.BehaviorSubject(c.params), new rxjs.BehaviorSubject(c.queryParams), new rxjs.BehaviorSubject(c.fragment), new rxjs.BehaviorSubject(c.data), c.outlet, c.component, c);
  1953. }
  1954. /**
  1955. * @license
  1956. * Copyright Google Inc. All Rights Reserved.
  1957. *
  1958. * Use of this source code is governed by an MIT-style license that can be
  1959. * found in the LICENSE file at https://angular.io/license
  1960. */
  1961. function createUrlTree(route, urlTree, commands, queryParams, fragment) {
  1962. if (commands.length === 0) {
  1963. return tree(urlTree.root, urlTree.root, urlTree, queryParams, fragment);
  1964. }
  1965. var nav = computeNavigation(commands);
  1966. if (nav.toRoot()) {
  1967. return tree(urlTree.root, new UrlSegmentGroup([], {}), urlTree, queryParams, fragment);
  1968. }
  1969. var startingPosition = findStartingPosition(nav, urlTree, route);
  1970. var segmentGroup = startingPosition.processChildren ?
  1971. updateSegmentGroupChildren(startingPosition.segmentGroup, startingPosition.index, nav.commands) :
  1972. updateSegmentGroup(startingPosition.segmentGroup, startingPosition.index, nav.commands);
  1973. return tree(startingPosition.segmentGroup, segmentGroup, urlTree, queryParams, fragment);
  1974. }
  1975. function isMatrixParams(command) {
  1976. return typeof command === 'object' && command != null && !command.outlets && !command.segmentPath;
  1977. }
  1978. function tree(oldSegmentGroup, newSegmentGroup, urlTree, queryParams, fragment) {
  1979. var qp = {};
  1980. if (queryParams) {
  1981. forEach(queryParams, function (value, name) {
  1982. qp[name] = Array.isArray(value) ? value.map(function (v) { return "" + v; }) : "" + value;
  1983. });
  1984. }
  1985. if (urlTree.root === oldSegmentGroup) {
  1986. return new UrlTree(newSegmentGroup, qp, fragment);
  1987. }
  1988. return new UrlTree(replaceSegment(urlTree.root, oldSegmentGroup, newSegmentGroup), qp, fragment);
  1989. }
  1990. function replaceSegment(current, oldSegment, newSegment) {
  1991. var children = {};
  1992. forEach(current.children, function (c, outletName) {
  1993. if (c === oldSegment) {
  1994. children[outletName] = newSegment;
  1995. }
  1996. else {
  1997. children[outletName] = replaceSegment(c, oldSegment, newSegment);
  1998. }
  1999. });
  2000. return new UrlSegmentGroup(current.segments, children);
  2001. }
  2002. var Navigation = /** @class */ (function () {
  2003. function Navigation(isAbsolute, numberOfDoubleDots, commands) {
  2004. this.isAbsolute = isAbsolute;
  2005. this.numberOfDoubleDots = numberOfDoubleDots;
  2006. this.commands = commands;
  2007. if (isAbsolute && commands.length > 0 && isMatrixParams(commands[0])) {
  2008. throw new Error('Root segment cannot have matrix parameters');
  2009. }
  2010. var cmdWithOutlet = commands.find(function (c) { return typeof c === 'object' && c != null && c.outlets; });
  2011. if (cmdWithOutlet && cmdWithOutlet !== last(commands)) {
  2012. throw new Error('{outlets:{}} has to be the last command');
  2013. }
  2014. }
  2015. Navigation.prototype.toRoot = function () {
  2016. return this.isAbsolute && this.commands.length === 1 && this.commands[0] == '/';
  2017. };
  2018. return Navigation;
  2019. }());
  2020. /** Transforms commands to a normalized `Navigation` */
  2021. function computeNavigation(commands) {
  2022. if ((typeof commands[0] === 'string') && commands.length === 1 && commands[0] === '/') {
  2023. return new Navigation(true, 0, commands);
  2024. }
  2025. var numberOfDoubleDots = 0;
  2026. var isAbsolute = false;
  2027. var res = commands.reduce(function (res, cmd, cmdIdx) {
  2028. if (typeof cmd === 'object' && cmd != null) {
  2029. if (cmd.outlets) {
  2030. var outlets_1 = {};
  2031. forEach(cmd.outlets, function (commands, name) {
  2032. outlets_1[name] = typeof commands === 'string' ? commands.split('/') : commands;
  2033. });
  2034. return __spread(res, [{ outlets: outlets_1 }]);
  2035. }
  2036. if (cmd.segmentPath) {
  2037. return __spread(res, [cmd.segmentPath]);
  2038. }
  2039. }
  2040. if (!(typeof cmd === 'string')) {
  2041. return __spread(res, [cmd]);
  2042. }
  2043. if (cmdIdx === 0) {
  2044. cmd.split('/').forEach(function (urlPart, partIndex) {
  2045. if (partIndex == 0 && urlPart === '.') ;
  2046. else if (partIndex == 0 && urlPart === '') { // '/a'
  2047. isAbsolute = true;
  2048. }
  2049. else if (urlPart === '..') { // '../a'
  2050. numberOfDoubleDots++;
  2051. }
  2052. else if (urlPart != '') {
  2053. res.push(urlPart);
  2054. }
  2055. });
  2056. return res;
  2057. }
  2058. return __spread(res, [cmd]);
  2059. }, []);
  2060. return new Navigation(isAbsolute, numberOfDoubleDots, res);
  2061. }
  2062. var Position = /** @class */ (function () {
  2063. function Position(segmentGroup, processChildren, index) {
  2064. this.segmentGroup = segmentGroup;
  2065. this.processChildren = processChildren;
  2066. this.index = index;
  2067. }
  2068. return Position;
  2069. }());
  2070. function findStartingPosition(nav, tree, route) {
  2071. if (nav.isAbsolute) {
  2072. return new Position(tree.root, true, 0);
  2073. }
  2074. if (route.snapshot._lastPathIndex === -1) {
  2075. return new Position(route.snapshot._urlSegment, true, 0);
  2076. }
  2077. var modifier = isMatrixParams(nav.commands[0]) ? 0 : 1;
  2078. var index = route.snapshot._lastPathIndex + modifier;
  2079. return createPositionApplyingDoubleDots(route.snapshot._urlSegment, index, nav.numberOfDoubleDots);
  2080. }
  2081. function createPositionApplyingDoubleDots(group, index, numberOfDoubleDots) {
  2082. var g = group;
  2083. var ci = index;
  2084. var dd = numberOfDoubleDots;
  2085. while (dd > ci) {
  2086. dd -= ci;
  2087. g = g.parent;
  2088. if (!g) {
  2089. throw new Error('Invalid number of \'../\'');
  2090. }
  2091. ci = g.segments.length;
  2092. }
  2093. return new Position(g, false, ci - dd);
  2094. }
  2095. function getPath(command) {
  2096. if (typeof command === 'object' && command != null && command.outlets) {
  2097. return command.outlets[PRIMARY_OUTLET];
  2098. }
  2099. return "" + command;
  2100. }
  2101. function getOutlets(commands) {
  2102. var _a, _b;
  2103. if (!(typeof commands[0] === 'object'))
  2104. return _a = {}, _a[PRIMARY_OUTLET] = commands, _a;
  2105. if (commands[0].outlets === undefined)
  2106. return _b = {}, _b[PRIMARY_OUTLET] = commands, _b;
  2107. return commands[0].outlets;
  2108. }
  2109. function updateSegmentGroup(segmentGroup, startIndex, commands) {
  2110. if (!segmentGroup) {
  2111. segmentGroup = new UrlSegmentGroup([], {});
  2112. }
  2113. if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
  2114. return updateSegmentGroupChildren(segmentGroup, startIndex, commands);
  2115. }
  2116. var m = prefixedWith(segmentGroup, startIndex, commands);
  2117. var slicedCommands = commands.slice(m.commandIndex);
  2118. if (m.match && m.pathIndex < segmentGroup.segments.length) {
  2119. var g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {});
  2120. g.children[PRIMARY_OUTLET] =
  2121. new UrlSegmentGroup(segmentGroup.segments.slice(m.pathIndex), segmentGroup.children);
  2122. return updateSegmentGroupChildren(g, 0, slicedCommands);
  2123. }
  2124. else if (m.match && slicedCommands.length === 0) {
  2125. return new UrlSegmentGroup(segmentGroup.segments, {});
  2126. }
  2127. else if (m.match && !segmentGroup.hasChildren()) {
  2128. return createNewSegmentGroup(segmentGroup, startIndex, commands);
  2129. }
  2130. else if (m.match) {
  2131. return updateSegmentGroupChildren(segmentGroup, 0, slicedCommands);
  2132. }
  2133. else {
  2134. return createNewSegmentGroup(segmentGroup, startIndex, commands);
  2135. }
  2136. }
  2137. function updateSegmentGroupChildren(segmentGroup, startIndex, commands) {
  2138. if (commands.length === 0) {
  2139. return new UrlSegmentGroup(segmentGroup.segments, {});
  2140. }
  2141. else {
  2142. var outlets_2 = getOutlets(commands);
  2143. var children_1 = {};
  2144. forEach(outlets_2, function (commands, outlet) {
  2145. if (commands !== null) {
  2146. children_1[outlet] = updateSegmentGroup(segmentGroup.children[outlet], startIndex, commands);
  2147. }
  2148. });
  2149. forEach(segmentGroup.children, function (child, childOutlet) {
  2150. if (outlets_2[childOutlet] === undefined) {
  2151. children_1[childOutlet] = child;
  2152. }
  2153. });
  2154. return new UrlSegmentGroup(segmentGroup.segments, children_1);
  2155. }
  2156. }
  2157. function prefixedWith(segmentGroup, startIndex, commands) {
  2158. var currentCommandIndex = 0;
  2159. var currentPathIndex = startIndex;
  2160. var noMatch = { match: false, pathIndex: 0, commandIndex: 0 };
  2161. while (currentPathIndex < segmentGroup.segments.length) {
  2162. if (currentCommandIndex >= commands.length)
  2163. return noMatch;
  2164. var path = segmentGroup.segments[currentPathIndex];
  2165. var curr = getPath(commands[currentCommandIndex]);
  2166. var next = currentCommandIndex < commands.length - 1 ? commands[currentCommandIndex + 1] : null;
  2167. if (currentPathIndex > 0 && curr === undefined)
  2168. break;
  2169. if (curr && next && (typeof next === 'object') && next.outlets === undefined) {
  2170. if (!compare(curr, next, path))
  2171. return noMatch;
  2172. currentCommandIndex += 2;
  2173. }
  2174. else {
  2175. if (!compare(curr, {}, path))
  2176. return noMatch;
  2177. currentCommandIndex++;
  2178. }
  2179. currentPathIndex++;
  2180. }
  2181. return { match: true, pathIndex: currentPathIndex, commandIndex: currentCommandIndex };
  2182. }
  2183. function createNewSegmentGroup(segmentGroup, startIndex, commands) {
  2184. var paths = segmentGroup.segments.slice(0, startIndex);
  2185. var i = 0;
  2186. while (i < commands.length) {
  2187. if (typeof commands[i] === 'object' && commands[i].outlets !== undefined) {
  2188. var children = createNewSegmentChildren(commands[i].outlets);
  2189. return new UrlSegmentGroup(paths, children);
  2190. }
  2191. // if we start with an object literal, we need to reuse the path part from the segment
  2192. if (i === 0 && isMatrixParams(commands[0])) {
  2193. var p = segmentGroup.segments[startIndex];
  2194. paths.push(new UrlSegment(p.path, commands[0]));
  2195. i++;
  2196. continue;
  2197. }
  2198. var curr = getPath(commands[i]);
  2199. var next = (i < commands.length - 1) ? commands[i + 1] : null;
  2200. if (curr && next && isMatrixParams(next)) {
  2201. paths.push(new UrlSegment(curr, stringify(next)));
  2202. i += 2;
  2203. }
  2204. else {
  2205. paths.push(new UrlSegment(curr, {}));
  2206. i++;
  2207. }
  2208. }
  2209. return new UrlSegmentGroup(paths, {});
  2210. }
  2211. function createNewSegmentChildren(outlets) {
  2212. var children = {};
  2213. forEach(outlets, function (commands, outlet) {
  2214. if (commands !== null) {
  2215. children[outlet] = createNewSegmentGroup(new UrlSegmentGroup([], {}), 0, commands);
  2216. }
  2217. });
  2218. return children;
  2219. }
  2220. function stringify(params) {
  2221. var res = {};
  2222. forEach(params, function (v, k) { return res[k] = "" + v; });
  2223. return res;
  2224. }
  2225. function compare(path, params, segment) {
  2226. return path == segment.path && shallowEqual(params, segment.parameters);
  2227. }
  2228. /**
  2229. * @license
  2230. * Copyright Google Inc. All Rights Reserved.
  2231. *
  2232. * Use of this source code is governed by an MIT-style license that can be
  2233. * found in the LICENSE file at https://angular.io/license
  2234. */
  2235. var activateRoutes = function (rootContexts, routeReuseStrategy, forwardEvent) {
  2236. return operators.map(function (t) {
  2237. new ActivateRoutes(routeReuseStrategy, t.targetRouterState, t.currentRouterState, forwardEvent)
  2238. .activate(rootContexts);
  2239. return t;
  2240. });
  2241. };
  2242. var ActivateRoutes = /** @class */ (function () {
  2243. function ActivateRoutes(routeReuseStrategy, futureState, currState, forwardEvent) {
  2244. this.routeReuseStrategy = routeReuseStrategy;
  2245. this.futureState = futureState;
  2246. this.currState = currState;
  2247. this.forwardEvent = forwardEvent;
  2248. }
  2249. ActivateRoutes.prototype.activate = function (parentContexts) {
  2250. var futureRoot = this.futureState._root;
  2251. var currRoot = this.currState ? this.currState._root : null;
  2252. this.deactivateChildRoutes(futureRoot, currRoot, parentContexts);
  2253. advanceActivatedRoute(this.futureState.root);
  2254. this.activateChildRoutes(futureRoot, currRoot, parentContexts);
  2255. };
  2256. // De-activate the child route that are not re-used for the future state
  2257. ActivateRoutes.prototype.deactivateChildRoutes = function (futureNode, currNode, contexts) {
  2258. var _this = this;
  2259. var children = nodeChildrenAsMap(currNode);
  2260. // Recurse on the routes active in the future state to de-activate deeper children
  2261. futureNode.children.forEach(function (futureChild) {
  2262. var childOutletName = futureChild.value.outlet;
  2263. _this.deactivateRoutes(futureChild, children[childOutletName], contexts);
  2264. delete children[childOutletName];
  2265. });
  2266. // De-activate the routes that will not be re-used
  2267. forEach(children, function (v, childName) {
  2268. _this.deactivateRouteAndItsChildren(v, contexts);
  2269. });
  2270. };
  2271. ActivateRoutes.prototype.deactivateRoutes = function (futureNode, currNode, parentContext) {
  2272. var future = futureNode.value;
  2273. var curr = currNode ? currNode.value : null;
  2274. if (future === curr) {
  2275. // Reusing the node, check to see if the children need to be de-activated
  2276. if (future.component) {
  2277. // If we have a normal route, we need to go through an outlet.
  2278. var context = parentContext.getContext(future.outlet);
  2279. if (context) {
  2280. this.deactivateChildRoutes(futureNode, currNode, context.children);
  2281. }
  2282. }
  2283. else {
  2284. // if we have a componentless route, we recurse but keep the same outlet map.
  2285. this.deactivateChildRoutes(futureNode, currNode, parentContext);
  2286. }
  2287. }
  2288. else {
  2289. if (curr) {
  2290. // Deactivate the current route which will not be re-used
  2291. this.deactivateRouteAndItsChildren(currNode, parentContext);
  2292. }
  2293. }
  2294. };
  2295. ActivateRoutes.prototype.deactivateRouteAndItsChildren = function (route, parentContexts) {
  2296. if (this.routeReuseStrategy.shouldDetach(route.value.snapshot)) {
  2297. this.detachAndStoreRouteSubtree(route, parentContexts);
  2298. }
  2299. else {
  2300. this.deactivateRouteAndOutlet(route, parentContexts);
  2301. }
  2302. };
  2303. ActivateRoutes.prototype.detachAndStoreRouteSubtree = function (route, parentContexts) {
  2304. var context = parentContexts.getContext(route.value.outlet);
  2305. if (context && context.outlet) {
  2306. var componentRef = context.outlet.detach();
  2307. var contexts = context.children.onOutletDeactivated();
  2308. this.routeReuseStrategy.store(route.value.snapshot, { componentRef: componentRef, route: route, contexts: contexts });
  2309. }
  2310. };
  2311. ActivateRoutes.prototype.deactivateRouteAndOutlet = function (route, parentContexts) {
  2312. var _this = this;
  2313. var context = parentContexts.getContext(route.value.outlet);
  2314. if (context) {
  2315. var children = nodeChildrenAsMap(route);
  2316. var contexts_1 = route.value.component ? context.children : parentContexts;
  2317. forEach(children, function (v, k) { return _this.deactivateRouteAndItsChildren(v, contexts_1); });
  2318. if (context.outlet) {
  2319. // Destroy the component
  2320. context.outlet.deactivate();
  2321. // Destroy the contexts for all the outlets that were in the component
  2322. context.children.onOutletDeactivated();
  2323. }
  2324. }
  2325. };
  2326. ActivateRoutes.prototype.activateChildRoutes = function (futureNode, currNode, contexts) {
  2327. var _this = this;
  2328. var children = nodeChildrenAsMap(currNode);
  2329. futureNode.children.forEach(function (c) {
  2330. _this.activateRoutes(c, children[c.value.outlet], contexts);
  2331. _this.forwardEvent(new ActivationEnd(c.value.snapshot));
  2332. });
  2333. if (futureNode.children.length) {
  2334. this.forwardEvent(new ChildActivationEnd(futureNode.value.snapshot));
  2335. }
  2336. };
  2337. ActivateRoutes.prototype.activateRoutes = function (futureNode, currNode, parentContexts) {
  2338. var future = futureNode.value;
  2339. var curr = currNode ? currNode.value : null;
  2340. advanceActivatedRoute(future);
  2341. // reusing the node
  2342. if (future === curr) {
  2343. if (future.component) {
  2344. // If we have a normal route, we need to go through an outlet.
  2345. var context = parentContexts.getOrCreateContext(future.outlet);
  2346. this.activateChildRoutes(futureNode, currNode, context.children);
  2347. }
  2348. else {
  2349. // if we have a componentless route, we recurse but keep the same outlet map.
  2350. this.activateChildRoutes(futureNode, currNode, parentContexts);
  2351. }
  2352. }
  2353. else {
  2354. if (future.component) {
  2355. // if we have a normal route, we need to place the component into the outlet and recurse.
  2356. var context = parentContexts.getOrCreateContext(future.outlet);
  2357. if (this.routeReuseStrategy.shouldAttach(future.snapshot)) {
  2358. var stored = this.routeReuseStrategy.retrieve(future.snapshot);
  2359. this.routeReuseStrategy.store(future.snapshot, null);
  2360. context.children.onOutletReAttached(stored.contexts);
  2361. context.attachRef = stored.componentRef;
  2362. context.route = stored.route.value;
  2363. if (context.outlet) {
  2364. // Attach right away when the outlet has already been instantiated
  2365. // Otherwise attach from `RouterOutlet.ngOnInit` when it is instantiated
  2366. context.outlet.attach(stored.componentRef, stored.route.value);
  2367. }
  2368. advanceActivatedRouteNodeAndItsChildren(stored.route);
  2369. }
  2370. else {
  2371. var config = parentLoadedConfig(future.snapshot);
  2372. var cmpFactoryResolver = config ? config.module.componentFactoryResolver : null;
  2373. context.attachRef = null;
  2374. context.route = future;
  2375. context.resolver = cmpFactoryResolver;
  2376. if (context.outlet) {
  2377. // Activate the outlet when it has already been instantiated
  2378. // Otherwise it will get activated from its `ngOnInit` when instantiated
  2379. context.outlet.activateWith(future, cmpFactoryResolver);
  2380. }
  2381. this.activateChildRoutes(futureNode, null, context.children);
  2382. }
  2383. }
  2384. else {
  2385. // if we have a componentless route, we recurse but keep the same outlet map.
  2386. this.activateChildRoutes(futureNode, null, parentContexts);
  2387. }
  2388. }
  2389. };
  2390. return ActivateRoutes;
  2391. }());
  2392. function advanceActivatedRouteNodeAndItsChildren(node) {
  2393. advanceActivatedRoute(node.value);
  2394. node.children.forEach(advanceActivatedRouteNodeAndItsChildren);
  2395. }
  2396. function parentLoadedConfig(snapshot) {
  2397. for (var s = snapshot.parent; s; s = s.parent) {
  2398. var route = s.routeConfig;
  2399. if (route && route._loadedConfig)
  2400. return route._loadedConfig;
  2401. if (route && route.component)
  2402. return null;
  2403. }
  2404. return null;
  2405. }
  2406. /**
  2407. * @license
  2408. * Copyright Google Inc. All Rights Reserved.
  2409. *
  2410. * Use of this source code is governed by an MIT-style license that can be
  2411. * found in the LICENSE file at https://angular.io/license
  2412. */
  2413. /**
  2414. * Simple function check, but generic so type inference will flow. Example:
  2415. *
  2416. * function product(a: number, b: number) {
  2417. * return a * b;
  2418. * }
  2419. *
  2420. * if (isFunction<product>(fn)) {
  2421. * return fn(1, 2);
  2422. * } else {
  2423. * throw "Must provide the `product` function";
  2424. * }
  2425. */
  2426. function isFunction(v) {
  2427. return typeof v === 'function';
  2428. }
  2429. function isBoolean(v) {
  2430. return typeof v === 'boolean';
  2431. }
  2432. function isUrlTree(v) {
  2433. return v instanceof UrlTree;
  2434. }
  2435. function isCanLoad(guard) {
  2436. return guard && isFunction(guard.canLoad);
  2437. }
  2438. function isCanActivate(guard) {
  2439. return guard && isFunction(guard.canActivate);
  2440. }
  2441. function isCanActivateChild(guard) {
  2442. return guard && isFunction(guard.canActivateChild);
  2443. }
  2444. function isCanDeactivate(guard) {
  2445. return guard && isFunction(guard.canDeactivate);
  2446. }
  2447. /**
  2448. * @license
  2449. * Copyright Google Inc. All Rights Reserved.
  2450. *
  2451. * Use of this source code is governed by an MIT-style license that can be
  2452. * found in the LICENSE file at https://angular.io/license
  2453. */
  2454. var NoMatch = /** @class */ (function () {
  2455. function NoMatch(segmentGroup) {
  2456. this.segmentGroup = segmentGroup || null;
  2457. }
  2458. return NoMatch;
  2459. }());
  2460. var AbsoluteRedirect = /** @class */ (function () {
  2461. function AbsoluteRedirect(urlTree) {
  2462. this.urlTree = urlTree;
  2463. }
  2464. return AbsoluteRedirect;
  2465. }());
  2466. function noMatch(segmentGroup) {
  2467. return new rxjs.Observable(function (obs) { return obs.error(new NoMatch(segmentGroup)); });
  2468. }
  2469. function absoluteRedirect(newTree) {
  2470. return new rxjs.Observable(function (obs) { return obs.error(new AbsoluteRedirect(newTree)); });
  2471. }
  2472. function namedOutletsRedirect(redirectTo) {
  2473. return new rxjs.Observable(function (obs) { return obs.error(new Error("Only absolute redirects can have named outlets. redirectTo: '" + redirectTo + "'")); });
  2474. }
  2475. function canLoadFails(route) {
  2476. return new rxjs.Observable(function (obs) { return obs.error(navigationCancelingError("Cannot load children because the guard of the route \"path: '" + route.path + "'\" returned false")); });
  2477. }
  2478. /**
  2479. * Returns the `UrlTree` with the redirection applied.
  2480. *
  2481. * Lazy modules are loaded along the way.
  2482. */
  2483. function applyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) {
  2484. return new ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config).apply();
  2485. }
  2486. var ApplyRedirects = /** @class */ (function () {
  2487. function ApplyRedirects(moduleInjector, configLoader, urlSerializer, urlTree, config) {
  2488. this.configLoader = configLoader;
  2489. this.urlSerializer = urlSerializer;
  2490. this.urlTree = urlTree;
  2491. this.config = config;
  2492. this.allowRedirects = true;
  2493. this.ngModule = moduleInjector.get(core.NgModuleRef);
  2494. }
  2495. ApplyRedirects.prototype.apply = function () {
  2496. var _this = this;
  2497. var expanded$ = this.expandSegmentGroup(this.ngModule, this.config, this.urlTree.root, PRIMARY_OUTLET);
  2498. var urlTrees$ = expanded$.pipe(operators.map(function (rootSegmentGroup) { return _this.createUrlTree(rootSegmentGroup, _this.urlTree.queryParams, _this.urlTree.fragment); }));
  2499. return urlTrees$.pipe(operators.catchError(function (e) {
  2500. if (e instanceof AbsoluteRedirect) {
  2501. // after an absolute redirect we do not apply any more redirects!
  2502. _this.allowRedirects = false;
  2503. // we need to run matching, so we can fetch all lazy-loaded modules
  2504. return _this.match(e.urlTree);
  2505. }
  2506. if (e instanceof NoMatch) {
  2507. throw _this.noMatchError(e);
  2508. }
  2509. throw e;
  2510. }));
  2511. };
  2512. ApplyRedirects.prototype.match = function (tree) {
  2513. var _this = this;
  2514. var expanded$ = this.expandSegmentGroup(this.ngModule, this.config, tree.root, PRIMARY_OUTLET);
  2515. var mapped$ = expanded$.pipe(operators.map(function (rootSegmentGroup) {
  2516. return _this.createUrlTree(rootSegmentGroup, tree.queryParams, tree.fragment);
  2517. }));
  2518. return mapped$.pipe(operators.catchError(function (e) {
  2519. if (e instanceof NoMatch) {
  2520. throw _this.noMatchError(e);
  2521. }
  2522. throw e;
  2523. }));
  2524. };
  2525. ApplyRedirects.prototype.noMatchError = function (e) {
  2526. return new Error("Cannot match any routes. URL Segment: '" + e.segmentGroup + "'");
  2527. };
  2528. ApplyRedirects.prototype.createUrlTree = function (rootCandidate, queryParams, fragment) {
  2529. var _a;
  2530. var root = rootCandidate.segments.length > 0 ?
  2531. new UrlSegmentGroup([], (_a = {}, _a[PRIMARY_OUTLET] = rootCandidate, _a)) :
  2532. rootCandidate;
  2533. return new UrlTree(root, queryParams, fragment);
  2534. };
  2535. ApplyRedirects.prototype.expandSegmentGroup = function (ngModule, routes, segmentGroup, outlet) {
  2536. if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
  2537. return this.expandChildren(ngModule, routes, segmentGroup)
  2538. .pipe(operators.map(function (children) { return new UrlSegmentGroup([], children); }));
  2539. }
  2540. return this.expandSegment(ngModule, segmentGroup, routes, segmentGroup.segments, outlet, true);
  2541. };
  2542. // Recursively expand segment groups for all the child outlets
  2543. ApplyRedirects.prototype.expandChildren = function (ngModule, routes, segmentGroup) {
  2544. var _this = this;
  2545. return waitForMap(segmentGroup.children, function (childOutlet, child) { return _this.expandSegmentGroup(ngModule, routes, child, childOutlet); });
  2546. };
  2547. ApplyRedirects.prototype.expandSegment = function (ngModule, segmentGroup, routes, segments, outlet, allowRedirects) {
  2548. var _this = this;
  2549. return rxjs.of.apply(void 0, __spread(routes)).pipe(operators.map(function (r) {
  2550. var expanded$ = _this.expandSegmentAgainstRoute(ngModule, segmentGroup, routes, r, segments, outlet, allowRedirects);
  2551. return expanded$.pipe(operators.catchError(function (e) {
  2552. if (e instanceof NoMatch) {
  2553. // TODO(i): this return type doesn't match the declared Observable<UrlSegmentGroup> -
  2554. // talk to Jason
  2555. return rxjs.of(null);
  2556. }
  2557. throw e;
  2558. }));
  2559. }), operators.concatAll(), operators.first(function (s) { return !!s; }), operators.catchError(function (e, _) {
  2560. if (e instanceof rxjs.EmptyError || e.name === 'EmptyError') {
  2561. if (_this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
  2562. return rxjs.of(new UrlSegmentGroup([], {}));
  2563. }
  2564. throw new NoMatch(segmentGroup);
  2565. }
  2566. throw e;
  2567. }));
  2568. };
  2569. ApplyRedirects.prototype.noLeftoversInUrl = function (segmentGroup, segments, outlet) {
  2570. return segments.length === 0 && !segmentGroup.children[outlet];
  2571. };
  2572. ApplyRedirects.prototype.expandSegmentAgainstRoute = function (ngModule, segmentGroup, routes, route, paths, outlet, allowRedirects) {
  2573. if (getOutlet(route) !== outlet) {
  2574. return noMatch(segmentGroup);
  2575. }
  2576. if (route.redirectTo === undefined) {
  2577. return this.matchSegmentAgainstRoute(ngModule, segmentGroup, route, paths);
  2578. }
  2579. if (allowRedirects && this.allowRedirects) {
  2580. return this.expandSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, paths, outlet);
  2581. }
  2582. return noMatch(segmentGroup);
  2583. };
  2584. ApplyRedirects.prototype.expandSegmentAgainstRouteUsingRedirect = function (ngModule, segmentGroup, routes, route, segments, outlet) {
  2585. if (route.path === '**') {
  2586. return this.expandWildCardWithParamsAgainstRouteUsingRedirect(ngModule, routes, route, outlet);
  2587. }
  2588. return this.expandRegularSegmentAgainstRouteUsingRedirect(ngModule, segmentGroup, routes, route, segments, outlet);
  2589. };
  2590. ApplyRedirects.prototype.expandWildCardWithParamsAgainstRouteUsingRedirect = function (ngModule, routes, route, outlet) {
  2591. var _this = this;
  2592. var newTree = this.applyRedirectCommands([], route.redirectTo, {});
  2593. if (route.redirectTo.startsWith('/')) {
  2594. return absoluteRedirect(newTree);
  2595. }
  2596. return this.lineralizeSegments(route, newTree).pipe(operators.mergeMap(function (newSegments) {
  2597. var group = new UrlSegmentGroup(newSegments, {});
  2598. return _this.expandSegment(ngModule, group, routes, newSegments, outlet, false);
  2599. }));
  2600. };
  2601. ApplyRedirects.prototype.expandRegularSegmentAgainstRouteUsingRedirect = function (ngModule, segmentGroup, routes, route, segments, outlet) {
  2602. var _this = this;
  2603. var _a = match(segmentGroup, route, segments), matched = _a.matched, consumedSegments = _a.consumedSegments, lastChild = _a.lastChild, positionalParamSegments = _a.positionalParamSegments;
  2604. if (!matched)
  2605. return noMatch(segmentGroup);
  2606. var newTree = this.applyRedirectCommands(consumedSegments, route.redirectTo, positionalParamSegments);
  2607. if (route.redirectTo.startsWith('/')) {
  2608. return absoluteRedirect(newTree);
  2609. }
  2610. return this.lineralizeSegments(route, newTree).pipe(operators.mergeMap(function (newSegments) {
  2611. return _this.expandSegment(ngModule, segmentGroup, routes, newSegments.concat(segments.slice(lastChild)), outlet, false);
  2612. }));
  2613. };
  2614. ApplyRedirects.prototype.matchSegmentAgainstRoute = function (ngModule, rawSegmentGroup, route, segments) {
  2615. var _this = this;
  2616. if (route.path === '**') {
  2617. if (route.loadChildren) {
  2618. return this.configLoader.load(ngModule.injector, route)
  2619. .pipe(operators.map(function (cfg) {
  2620. route._loadedConfig = cfg;
  2621. return new UrlSegmentGroup(segments, {});
  2622. }));
  2623. }
  2624. return rxjs.of(new UrlSegmentGroup(segments, {}));
  2625. }
  2626. var _a = match(rawSegmentGroup, route, segments), matched = _a.matched, consumedSegments = _a.consumedSegments, lastChild = _a.lastChild;
  2627. if (!matched)
  2628. return noMatch(rawSegmentGroup);
  2629. var rawSlicedSegments = segments.slice(lastChild);
  2630. var childConfig$ = this.getChildConfig(ngModule, route, segments);
  2631. return childConfig$.pipe(operators.mergeMap(function (routerConfig) {
  2632. var childModule = routerConfig.module;
  2633. var childConfig = routerConfig.routes;
  2634. var _a = split(rawSegmentGroup, consumedSegments, rawSlicedSegments, childConfig), segmentGroup = _a.segmentGroup, slicedSegments = _a.slicedSegments;
  2635. if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
  2636. var expanded$_1 = _this.expandChildren(childModule, childConfig, segmentGroup);
  2637. return expanded$_1.pipe(operators.map(function (children) { return new UrlSegmentGroup(consumedSegments, children); }));
  2638. }
  2639. if (childConfig.length === 0 && slicedSegments.length === 0) {
  2640. return rxjs.of(new UrlSegmentGroup(consumedSegments, {}));
  2641. }
  2642. var expanded$ = _this.expandSegment(childModule, segmentGroup, childConfig, slicedSegments, PRIMARY_OUTLET, true);
  2643. return expanded$.pipe(operators.map(function (cs) {
  2644. return new UrlSegmentGroup(consumedSegments.concat(cs.segments), cs.children);
  2645. }));
  2646. }));
  2647. };
  2648. ApplyRedirects.prototype.getChildConfig = function (ngModule, route, segments) {
  2649. var _this = this;
  2650. if (route.children) {
  2651. // The children belong to the same module
  2652. return rxjs.of(new LoadedRouterConfig(route.children, ngModule));
  2653. }
  2654. if (route.loadChildren) {
  2655. // lazy children belong to the loaded module
  2656. if (route._loadedConfig !== undefined) {
  2657. return rxjs.of(route._loadedConfig);
  2658. }
  2659. return runCanLoadGuard(ngModule.injector, route, segments)
  2660. .pipe(operators.mergeMap(function (shouldLoad) {
  2661. if (shouldLoad) {
  2662. return _this.configLoader.load(ngModule.injector, route)
  2663. .pipe(operators.map(function (cfg) {
  2664. route._loadedConfig = cfg;
  2665. return cfg;
  2666. }));
  2667. }
  2668. return canLoadFails(route);
  2669. }));
  2670. }
  2671. return rxjs.of(new LoadedRouterConfig([], ngModule));
  2672. };
  2673. ApplyRedirects.prototype.lineralizeSegments = function (route, urlTree) {
  2674. var res = [];
  2675. var c = urlTree.root;
  2676. while (true) {
  2677. res = res.concat(c.segments);
  2678. if (c.numberOfChildren === 0) {
  2679. return rxjs.of(res);
  2680. }
  2681. if (c.numberOfChildren > 1 || !c.children[PRIMARY_OUTLET]) {
  2682. return namedOutletsRedirect(route.redirectTo);
  2683. }
  2684. c = c.children[PRIMARY_OUTLET];
  2685. }
  2686. };
  2687. ApplyRedirects.prototype.applyRedirectCommands = function (segments, redirectTo, posParams) {
  2688. return this.applyRedirectCreatreUrlTree(redirectTo, this.urlSerializer.parse(redirectTo), segments, posParams);
  2689. };
  2690. ApplyRedirects.prototype.applyRedirectCreatreUrlTree = function (redirectTo, urlTree, segments, posParams) {
  2691. var newRoot = this.createSegmentGroup(redirectTo, urlTree.root, segments, posParams);
  2692. return new UrlTree(newRoot, this.createQueryParams(urlTree.queryParams, this.urlTree.queryParams), urlTree.fragment);
  2693. };
  2694. ApplyRedirects.prototype.createQueryParams = function (redirectToParams, actualParams) {
  2695. var res = {};
  2696. forEach(redirectToParams, function (v, k) {
  2697. var copySourceValue = typeof v === 'string' && v.startsWith(':');
  2698. if (copySourceValue) {
  2699. var sourceName = v.substring(1);
  2700. res[k] = actualParams[sourceName];
  2701. }
  2702. else {
  2703. res[k] = v;
  2704. }
  2705. });
  2706. return res;
  2707. };
  2708. ApplyRedirects.prototype.createSegmentGroup = function (redirectTo, group, segments, posParams) {
  2709. var _this = this;
  2710. var updatedSegments = this.createSegments(redirectTo, group.segments, segments, posParams);
  2711. var children = {};
  2712. forEach(group.children, function (child, name) {
  2713. children[name] = _this.createSegmentGroup(redirectTo, child, segments, posParams);
  2714. });
  2715. return new UrlSegmentGroup(updatedSegments, children);
  2716. };
  2717. ApplyRedirects.prototype.createSegments = function (redirectTo, redirectToSegments, actualSegments, posParams) {
  2718. var _this = this;
  2719. return redirectToSegments.map(function (s) { return s.path.startsWith(':') ? _this.findPosParam(redirectTo, s, posParams) :
  2720. _this.findOrReturn(s, actualSegments); });
  2721. };
  2722. ApplyRedirects.prototype.findPosParam = function (redirectTo, redirectToUrlSegment, posParams) {
  2723. var pos = posParams[redirectToUrlSegment.path.substring(1)];
  2724. if (!pos)
  2725. throw new Error("Cannot redirect to '" + redirectTo + "'. Cannot find '" + redirectToUrlSegment.path + "'.");
  2726. return pos;
  2727. };
  2728. ApplyRedirects.prototype.findOrReturn = function (redirectToUrlSegment, actualSegments) {
  2729. var e_1, _a;
  2730. var idx = 0;
  2731. try {
  2732. for (var actualSegments_1 = __values(actualSegments), actualSegments_1_1 = actualSegments_1.next(); !actualSegments_1_1.done; actualSegments_1_1 = actualSegments_1.next()) {
  2733. var s = actualSegments_1_1.value;
  2734. if (s.path === redirectToUrlSegment.path) {
  2735. actualSegments.splice(idx);
  2736. return s;
  2737. }
  2738. idx++;
  2739. }
  2740. }
  2741. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  2742. finally {
  2743. try {
  2744. if (actualSegments_1_1 && !actualSegments_1_1.done && (_a = actualSegments_1.return)) _a.call(actualSegments_1);
  2745. }
  2746. finally { if (e_1) throw e_1.error; }
  2747. }
  2748. return redirectToUrlSegment;
  2749. };
  2750. return ApplyRedirects;
  2751. }());
  2752. function runCanLoadGuard(moduleInjector, route, segments) {
  2753. var canLoad = route.canLoad;
  2754. if (!canLoad || canLoad.length === 0)
  2755. return rxjs.of(true);
  2756. var obs = rxjs.from(canLoad).pipe(operators.map(function (injectionToken) {
  2757. var guard = moduleInjector.get(injectionToken);
  2758. var guardVal;
  2759. if (isCanLoad(guard)) {
  2760. guardVal = guard.canLoad(route, segments);
  2761. }
  2762. else if (isFunction(guard)) {
  2763. guardVal = guard(route, segments);
  2764. }
  2765. else {
  2766. throw new Error('Invalid CanLoad guard');
  2767. }
  2768. return wrapIntoObservable(guardVal);
  2769. }));
  2770. return obs.pipe(operators.concatAll(), operators.every(function (result) { return result === true; }));
  2771. }
  2772. function match(segmentGroup, route, segments) {
  2773. if (route.path === '') {
  2774. if ((route.pathMatch === 'full') && (segmentGroup.hasChildren() || segments.length > 0)) {
  2775. return { matched: false, consumedSegments: [], lastChild: 0, positionalParamSegments: {} };
  2776. }
  2777. return { matched: true, consumedSegments: [], lastChild: 0, positionalParamSegments: {} };
  2778. }
  2779. var matcher = route.matcher || defaultUrlMatcher;
  2780. var res = matcher(segments, segmentGroup, route);
  2781. if (!res) {
  2782. return {
  2783. matched: false,
  2784. consumedSegments: [],
  2785. lastChild: 0,
  2786. positionalParamSegments: {},
  2787. };
  2788. }
  2789. return {
  2790. matched: true,
  2791. consumedSegments: res.consumed,
  2792. lastChild: res.consumed.length,
  2793. positionalParamSegments: res.posParams,
  2794. };
  2795. }
  2796. function split(segmentGroup, consumedSegments, slicedSegments, config) {
  2797. if (slicedSegments.length > 0 &&
  2798. containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, slicedSegments, config)) {
  2799. var s = new UrlSegmentGroup(consumedSegments, createChildrenForEmptySegments(config, new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
  2800. return { segmentGroup: mergeTrivialChildren(s), slicedSegments: [] };
  2801. }
  2802. if (slicedSegments.length === 0 &&
  2803. containsEmptyPathRedirects(segmentGroup, slicedSegments, config)) {
  2804. var s = new UrlSegmentGroup(segmentGroup.segments, addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, config, segmentGroup.children));
  2805. return { segmentGroup: mergeTrivialChildren(s), slicedSegments: slicedSegments };
  2806. }
  2807. return { segmentGroup: segmentGroup, slicedSegments: slicedSegments };
  2808. }
  2809. function mergeTrivialChildren(s) {
  2810. if (s.numberOfChildren === 1 && s.children[PRIMARY_OUTLET]) {
  2811. var c = s.children[PRIMARY_OUTLET];
  2812. return new UrlSegmentGroup(s.segments.concat(c.segments), c.children);
  2813. }
  2814. return s;
  2815. }
  2816. function addEmptySegmentsToChildrenIfNeeded(segmentGroup, slicedSegments, routes, children) {
  2817. var e_2, _a;
  2818. var res = {};
  2819. try {
  2820. for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
  2821. var r = routes_1_1.value;
  2822. if (isEmptyPathRedirect(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) {
  2823. res[getOutlet(r)] = new UrlSegmentGroup([], {});
  2824. }
  2825. }
  2826. }
  2827. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  2828. finally {
  2829. try {
  2830. if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
  2831. }
  2832. finally { if (e_2) throw e_2.error; }
  2833. }
  2834. return __assign({}, children, res);
  2835. }
  2836. function createChildrenForEmptySegments(routes, primarySegmentGroup) {
  2837. var e_3, _a;
  2838. var res = {};
  2839. res[PRIMARY_OUTLET] = primarySegmentGroup;
  2840. try {
  2841. for (var routes_2 = __values(routes), routes_2_1 = routes_2.next(); !routes_2_1.done; routes_2_1 = routes_2.next()) {
  2842. var r = routes_2_1.value;
  2843. if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) {
  2844. res[getOutlet(r)] = new UrlSegmentGroup([], {});
  2845. }
  2846. }
  2847. }
  2848. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  2849. finally {
  2850. try {
  2851. if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
  2852. }
  2853. finally { if (e_3) throw e_3.error; }
  2854. }
  2855. return res;
  2856. }
  2857. function containsEmptyPathRedirectsWithNamedOutlets(segmentGroup, segments, routes) {
  2858. return routes.some(function (r) { return isEmptyPathRedirect(segmentGroup, segments, r) && getOutlet(r) !== PRIMARY_OUTLET; });
  2859. }
  2860. function containsEmptyPathRedirects(segmentGroup, segments, routes) {
  2861. return routes.some(function (r) { return isEmptyPathRedirect(segmentGroup, segments, r); });
  2862. }
  2863. function isEmptyPathRedirect(segmentGroup, segments, r) {
  2864. if ((segmentGroup.hasChildren() || segments.length > 0) && r.pathMatch === 'full') {
  2865. return false;
  2866. }
  2867. return r.path === '' && r.redirectTo !== undefined;
  2868. }
  2869. function getOutlet(route) {
  2870. return route.outlet || PRIMARY_OUTLET;
  2871. }
  2872. /**
  2873. * @license
  2874. * Copyright Google Inc. All Rights Reserved.
  2875. *
  2876. * Use of this source code is governed by an MIT-style license that can be
  2877. * found in the LICENSE file at https://angular.io/license
  2878. */
  2879. function applyRedirects$1(moduleInjector, configLoader, urlSerializer, config) {
  2880. return function (source) {
  2881. return source.pipe(operators.switchMap(function (t) { return applyRedirects(moduleInjector, configLoader, urlSerializer, t.extractedUrl, config)
  2882. .pipe(operators.map(function (urlAfterRedirects) { return (__assign({}, t, { urlAfterRedirects: urlAfterRedirects })); })); }));
  2883. };
  2884. }
  2885. /**
  2886. * @license
  2887. * Copyright Google Inc. All Rights Reserved.
  2888. *
  2889. * Use of this source code is governed by an MIT-style license that can be
  2890. * found in the LICENSE file at https://angular.io/license
  2891. */
  2892. var CanActivate = /** @class */ (function () {
  2893. function CanActivate(path) {
  2894. this.path = path;
  2895. this.route = this.path[this.path.length - 1];
  2896. }
  2897. return CanActivate;
  2898. }());
  2899. var CanDeactivate = /** @class */ (function () {
  2900. function CanDeactivate(component, route) {
  2901. this.component = component;
  2902. this.route = route;
  2903. }
  2904. return CanDeactivate;
  2905. }());
  2906. function getAllRouteGuards(future, curr, parentContexts) {
  2907. var futureRoot = future._root;
  2908. var currRoot = curr ? curr._root : null;
  2909. return getChildRouteGuards(futureRoot, currRoot, parentContexts, [futureRoot.value]);
  2910. }
  2911. function getCanActivateChild(p) {
  2912. var canActivateChild = p.routeConfig ? p.routeConfig.canActivateChild : null;
  2913. if (!canActivateChild || canActivateChild.length === 0)
  2914. return null;
  2915. return { node: p, guards: canActivateChild };
  2916. }
  2917. function getToken(token, snapshot, moduleInjector) {
  2918. var config = getClosestLoadedConfig(snapshot);
  2919. var injector = config ? config.module.injector : moduleInjector;
  2920. return injector.get(token);
  2921. }
  2922. function getClosestLoadedConfig(snapshot) {
  2923. if (!snapshot)
  2924. return null;
  2925. for (var s = snapshot.parent; s; s = s.parent) {
  2926. var route = s.routeConfig;
  2927. if (route && route._loadedConfig)
  2928. return route._loadedConfig;
  2929. }
  2930. return null;
  2931. }
  2932. function getChildRouteGuards(futureNode, currNode, contexts, futurePath, checks) {
  2933. if (checks === void 0) { checks = {
  2934. canDeactivateChecks: [],
  2935. canActivateChecks: []
  2936. }; }
  2937. var prevChildren = nodeChildrenAsMap(currNode);
  2938. // Process the children of the future route
  2939. futureNode.children.forEach(function (c) {
  2940. getRouteGuards(c, prevChildren[c.value.outlet], contexts, futurePath.concat([c.value]), checks);
  2941. delete prevChildren[c.value.outlet];
  2942. });
  2943. // Process any children left from the current route (not active for the future route)
  2944. forEach(prevChildren, function (v, k) {
  2945. return deactivateRouteAndItsChildren(v, contexts.getContext(k), checks);
  2946. });
  2947. return checks;
  2948. }
  2949. function getRouteGuards(futureNode, currNode, parentContexts, futurePath, checks) {
  2950. if (checks === void 0) { checks = {
  2951. canDeactivateChecks: [],
  2952. canActivateChecks: []
  2953. }; }
  2954. var future = futureNode.value;
  2955. var curr = currNode ? currNode.value : null;
  2956. var context = parentContexts ? parentContexts.getContext(futureNode.value.outlet) : null;
  2957. // reusing the node
  2958. if (curr && future.routeConfig === curr.routeConfig) {
  2959. var shouldRun = shouldRunGuardsAndResolvers(curr, future, future.routeConfig.runGuardsAndResolvers);
  2960. if (shouldRun) {
  2961. checks.canActivateChecks.push(new CanActivate(futurePath));
  2962. }
  2963. else {
  2964. // we need to set the data
  2965. future.data = curr.data;
  2966. future._resolvedData = curr._resolvedData;
  2967. }
  2968. // If we have a component, we need to go through an outlet.
  2969. if (future.component) {
  2970. getChildRouteGuards(futureNode, currNode, context ? context.children : null, futurePath, checks);
  2971. // if we have a componentless route, we recurse but keep the same outlet map.
  2972. }
  2973. else {
  2974. getChildRouteGuards(futureNode, currNode, parentContexts, futurePath, checks);
  2975. }
  2976. if (shouldRun) {
  2977. var component = context && context.outlet && context.outlet.component || null;
  2978. checks.canDeactivateChecks.push(new CanDeactivate(component, curr));
  2979. }
  2980. }
  2981. else {
  2982. if (curr) {
  2983. deactivateRouteAndItsChildren(currNode, context, checks);
  2984. }
  2985. checks.canActivateChecks.push(new CanActivate(futurePath));
  2986. // If we have a component, we need to go through an outlet.
  2987. if (future.component) {
  2988. getChildRouteGuards(futureNode, null, context ? context.children : null, futurePath, checks);
  2989. // if we have a componentless route, we recurse but keep the same outlet map.
  2990. }
  2991. else {
  2992. getChildRouteGuards(futureNode, null, parentContexts, futurePath, checks);
  2993. }
  2994. }
  2995. return checks;
  2996. }
  2997. function shouldRunGuardsAndResolvers(curr, future, mode) {
  2998. if (typeof mode === 'function') {
  2999. return mode(curr, future);
  3000. }
  3001. switch (mode) {
  3002. case 'pathParamsChange':
  3003. return !equalPath(curr.url, future.url);
  3004. case 'pathParamsOrQueryParamsChange':
  3005. return !equalPath(curr.url, future.url) ||
  3006. !shallowEqual(curr.queryParams, future.queryParams);
  3007. case 'always':
  3008. return true;
  3009. case 'paramsOrQueryParamsChange':
  3010. return !equalParamsAndUrlSegments(curr, future) ||
  3011. !shallowEqual(curr.queryParams, future.queryParams);
  3012. case 'paramsChange':
  3013. default:
  3014. return !equalParamsAndUrlSegments(curr, future);
  3015. }
  3016. }
  3017. function deactivateRouteAndItsChildren(route, context, checks) {
  3018. var children = nodeChildrenAsMap(route);
  3019. var r = route.value;
  3020. forEach(children, function (node, childName) {
  3021. if (!r.component) {
  3022. deactivateRouteAndItsChildren(node, context, checks);
  3023. }
  3024. else if (context) {
  3025. deactivateRouteAndItsChildren(node, context.children.getContext(childName), checks);
  3026. }
  3027. else {
  3028. deactivateRouteAndItsChildren(node, null, checks);
  3029. }
  3030. });
  3031. if (!r.component) {
  3032. checks.canDeactivateChecks.push(new CanDeactivate(null, r));
  3033. }
  3034. else if (context && context.outlet && context.outlet.isActivated) {
  3035. checks.canDeactivateChecks.push(new CanDeactivate(context.outlet.component, r));
  3036. }
  3037. else {
  3038. checks.canDeactivateChecks.push(new CanDeactivate(null, r));
  3039. }
  3040. }
  3041. /**
  3042. * @license
  3043. * Copyright Google Inc. All Rights Reserved.
  3044. *
  3045. * Use of this source code is governed by an MIT-style license that can be
  3046. * found in the LICENSE file at https://angular.io/license
  3047. */
  3048. var INITIAL_VALUE = Symbol('INITIAL_VALUE');
  3049. function prioritizedGuardValue() {
  3050. return operators.switchMap(function (obs) {
  3051. return rxjs.combineLatest.apply(void 0, __spread(obs.map(function (o) { return o.pipe(operators.take(1), operators.startWith(INITIAL_VALUE)); }))).pipe(operators.scan(function (acc, list) {
  3052. var isPending = false;
  3053. return list.reduce(function (innerAcc, val, i) {
  3054. if (innerAcc !== INITIAL_VALUE)
  3055. return innerAcc;
  3056. // Toggle pending flag if any values haven't been set yet
  3057. if (val === INITIAL_VALUE)
  3058. isPending = true;
  3059. // Any other return values are only valid if we haven't yet hit a pending call.
  3060. // This guarantees that in the case of a guard at the bottom of the tree that
  3061. // returns a redirect, we will wait for the higher priority guard at the top to
  3062. // finish before performing the redirect.
  3063. if (!isPending) {
  3064. // Early return when we hit a `false` value as that should always cancel
  3065. // navigation
  3066. if (val === false)
  3067. return val;
  3068. if (i === list.length - 1 || isUrlTree(val)) {
  3069. return val;
  3070. }
  3071. }
  3072. return innerAcc;
  3073. }, acc);
  3074. }, INITIAL_VALUE), operators.filter(function (item) { return item !== INITIAL_VALUE; }), operators.map(function (item) { return isUrlTree(item) ? item : item === true; }), //
  3075. operators.take(1));
  3076. });
  3077. }
  3078. /**
  3079. * @license
  3080. * Copyright Google Inc. All Rights Reserved.
  3081. *
  3082. * Use of this source code is governed by an MIT-style license that can be
  3083. * found in the LICENSE file at https://angular.io/license
  3084. */
  3085. function checkGuards(moduleInjector, forwardEvent) {
  3086. return function (source) {
  3087. return source.pipe(operators.mergeMap(function (t) {
  3088. var targetSnapshot = t.targetSnapshot, currentSnapshot = t.currentSnapshot, _a = t.guards, canActivateChecks = _a.canActivateChecks, canDeactivateChecks = _a.canDeactivateChecks;
  3089. if (canDeactivateChecks.length === 0 && canActivateChecks.length === 0) {
  3090. return rxjs.of(__assign({}, t, { guardsResult: true }));
  3091. }
  3092. return runCanDeactivateChecks(canDeactivateChecks, targetSnapshot, currentSnapshot, moduleInjector)
  3093. .pipe(operators.mergeMap(function (canDeactivate) {
  3094. return canDeactivate && isBoolean(canDeactivate) ?
  3095. runCanActivateChecks(targetSnapshot, canActivateChecks, moduleInjector, forwardEvent) :
  3096. rxjs.of(canDeactivate);
  3097. }), operators.map(function (guardsResult) { return (__assign({}, t, { guardsResult: guardsResult })); }));
  3098. }));
  3099. };
  3100. }
  3101. function runCanDeactivateChecks(checks, futureRSS, currRSS, moduleInjector) {
  3102. return rxjs.from(checks).pipe(operators.mergeMap(function (check) {
  3103. return runCanDeactivate(check.component, check.route, currRSS, futureRSS, moduleInjector);
  3104. }), operators.first(function (result) { return result !== true; }, true));
  3105. }
  3106. function runCanActivateChecks(futureSnapshot, checks, moduleInjector, forwardEvent) {
  3107. return rxjs.from(checks).pipe(operators.concatMap(function (check) {
  3108. return rxjs.from([
  3109. fireChildActivationStart(check.route.parent, forwardEvent),
  3110. fireActivationStart(check.route, forwardEvent),
  3111. runCanActivateChild(futureSnapshot, check.path, moduleInjector),
  3112. runCanActivate(futureSnapshot, check.route, moduleInjector)
  3113. ])
  3114. .pipe(operators.concatAll(), operators.first(function (result) {
  3115. return result !== true;
  3116. }, true));
  3117. }), operators.first(function (result) { return result !== true; }, true));
  3118. }
  3119. /**
  3120. * This should fire off `ActivationStart` events for each route being activated at this
  3121. * level.
  3122. * In other words, if you're activating `a` and `b` below, `path` will contain the
  3123. * `ActivatedRouteSnapshot`s for both and we will fire `ActivationStart` for both. Always
  3124. * return
  3125. * `true` so checks continue to run.
  3126. */
  3127. function fireActivationStart(snapshot, forwardEvent) {
  3128. if (snapshot !== null && forwardEvent) {
  3129. forwardEvent(new ActivationStart(snapshot));
  3130. }
  3131. return rxjs.of(true);
  3132. }
  3133. /**
  3134. * This should fire off `ChildActivationStart` events for each route being activated at this
  3135. * level.
  3136. * In other words, if you're activating `a` and `b` below, `path` will contain the
  3137. * `ActivatedRouteSnapshot`s for both and we will fire `ChildActivationStart` for both. Always
  3138. * return
  3139. * `true` so checks continue to run.
  3140. */
  3141. function fireChildActivationStart(snapshot, forwardEvent) {
  3142. if (snapshot !== null && forwardEvent) {
  3143. forwardEvent(new ChildActivationStart(snapshot));
  3144. }
  3145. return rxjs.of(true);
  3146. }
  3147. function runCanActivate(futureRSS, futureARS, moduleInjector) {
  3148. var canActivate = futureARS.routeConfig ? futureARS.routeConfig.canActivate : null;
  3149. if (!canActivate || canActivate.length === 0)
  3150. return rxjs.of(true);
  3151. var canActivateObservables = canActivate.map(function (c) {
  3152. return rxjs.defer(function () {
  3153. var guard = getToken(c, futureARS, moduleInjector);
  3154. var observable;
  3155. if (isCanActivate(guard)) {
  3156. observable = wrapIntoObservable(guard.canActivate(futureARS, futureRSS));
  3157. }
  3158. else if (isFunction(guard)) {
  3159. observable = wrapIntoObservable(guard(futureARS, futureRSS));
  3160. }
  3161. else {
  3162. throw new Error('Invalid CanActivate guard');
  3163. }
  3164. return observable.pipe(operators.first());
  3165. });
  3166. });
  3167. return rxjs.of(canActivateObservables).pipe(prioritizedGuardValue());
  3168. }
  3169. function runCanActivateChild(futureRSS, path, moduleInjector) {
  3170. var futureARS = path[path.length - 1];
  3171. var canActivateChildGuards = path.slice(0, path.length - 1)
  3172. .reverse()
  3173. .map(function (p) { return getCanActivateChild(p); })
  3174. .filter(function (_) { return _ !== null; });
  3175. var canActivateChildGuardsMapped = canActivateChildGuards.map(function (d) {
  3176. return rxjs.defer(function () {
  3177. var guardsMapped = d.guards.map(function (c) {
  3178. var guard = getToken(c, d.node, moduleInjector);
  3179. var observable;
  3180. if (isCanActivateChild(guard)) {
  3181. observable = wrapIntoObservable(guard.canActivateChild(futureARS, futureRSS));
  3182. }
  3183. else if (isFunction(guard)) {
  3184. observable = wrapIntoObservable(guard(futureARS, futureRSS));
  3185. }
  3186. else {
  3187. throw new Error('Invalid CanActivateChild guard');
  3188. }
  3189. return observable.pipe(operators.first());
  3190. });
  3191. return rxjs.of(guardsMapped).pipe(prioritizedGuardValue());
  3192. });
  3193. });
  3194. return rxjs.of(canActivateChildGuardsMapped).pipe(prioritizedGuardValue());
  3195. }
  3196. function runCanDeactivate(component, currARS, currRSS, futureRSS, moduleInjector) {
  3197. var canDeactivate = currARS && currARS.routeConfig ? currARS.routeConfig.canDeactivate : null;
  3198. if (!canDeactivate || canDeactivate.length === 0)
  3199. return rxjs.of(true);
  3200. var canDeactivateObservables = canDeactivate.map(function (c) {
  3201. var guard = getToken(c, currARS, moduleInjector);
  3202. var observable;
  3203. if (isCanDeactivate(guard)) {
  3204. observable =
  3205. wrapIntoObservable(guard.canDeactivate(component, currARS, currRSS, futureRSS));
  3206. }
  3207. else if (isFunction(guard)) {
  3208. observable = wrapIntoObservable(guard(component, currARS, currRSS, futureRSS));
  3209. }
  3210. else {
  3211. throw new Error('Invalid CanDeactivate guard');
  3212. }
  3213. return observable.pipe(operators.first());
  3214. });
  3215. return rxjs.of(canDeactivateObservables).pipe(prioritizedGuardValue());
  3216. }
  3217. /**
  3218. * @license
  3219. * Copyright Google Inc. All Rights Reserved.
  3220. *
  3221. * Use of this source code is governed by an MIT-style license that can be
  3222. * found in the LICENSE file at https://angular.io/license
  3223. */
  3224. var NoMatch$1 = /** @class */ (function () {
  3225. function NoMatch() {
  3226. }
  3227. return NoMatch;
  3228. }());
  3229. function recognize(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution) {
  3230. if (paramsInheritanceStrategy === void 0) { paramsInheritanceStrategy = 'emptyOnly'; }
  3231. if (relativeLinkResolution === void 0) { relativeLinkResolution = 'legacy'; }
  3232. return new Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution)
  3233. .recognize();
  3234. }
  3235. var Recognizer = /** @class */ (function () {
  3236. function Recognizer(rootComponentType, config, urlTree, url, paramsInheritanceStrategy, relativeLinkResolution) {
  3237. this.rootComponentType = rootComponentType;
  3238. this.config = config;
  3239. this.urlTree = urlTree;
  3240. this.url = url;
  3241. this.paramsInheritanceStrategy = paramsInheritanceStrategy;
  3242. this.relativeLinkResolution = relativeLinkResolution;
  3243. }
  3244. Recognizer.prototype.recognize = function () {
  3245. try {
  3246. var rootSegmentGroup = split$1(this.urlTree.root, [], [], this.config, this.relativeLinkResolution).segmentGroup;
  3247. var children = this.processSegmentGroup(this.config, rootSegmentGroup, PRIMARY_OUTLET);
  3248. var root = new ActivatedRouteSnapshot([], Object.freeze({}), Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, {}, PRIMARY_OUTLET, this.rootComponentType, null, this.urlTree.root, -1, {});
  3249. var rootNode = new TreeNode(root, children);
  3250. var routeState = new RouterStateSnapshot(this.url, rootNode);
  3251. this.inheritParamsAndData(routeState._root);
  3252. return rxjs.of(routeState);
  3253. }
  3254. catch (e) {
  3255. return new rxjs.Observable(function (obs) { return obs.error(e); });
  3256. }
  3257. };
  3258. Recognizer.prototype.inheritParamsAndData = function (routeNode) {
  3259. var _this = this;
  3260. var route = routeNode.value;
  3261. var i = inheritedParamsDataResolve(route, this.paramsInheritanceStrategy);
  3262. route.params = Object.freeze(i.params);
  3263. route.data = Object.freeze(i.data);
  3264. routeNode.children.forEach(function (n) { return _this.inheritParamsAndData(n); });
  3265. };
  3266. Recognizer.prototype.processSegmentGroup = function (config, segmentGroup, outlet) {
  3267. if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
  3268. return this.processChildren(config, segmentGroup);
  3269. }
  3270. return this.processSegment(config, segmentGroup, segmentGroup.segments, outlet);
  3271. };
  3272. Recognizer.prototype.processChildren = function (config, segmentGroup) {
  3273. var _this = this;
  3274. var children = mapChildrenIntoArray(segmentGroup, function (child, childOutlet) { return _this.processSegmentGroup(config, child, childOutlet); });
  3275. checkOutletNameUniqueness(children);
  3276. sortActivatedRouteSnapshots(children);
  3277. return children;
  3278. };
  3279. Recognizer.prototype.processSegment = function (config, segmentGroup, segments, outlet) {
  3280. var e_1, _a;
  3281. try {
  3282. for (var config_1 = __values(config), config_1_1 = config_1.next(); !config_1_1.done; config_1_1 = config_1.next()) {
  3283. var r = config_1_1.value;
  3284. try {
  3285. return this.processSegmentAgainstRoute(r, segmentGroup, segments, outlet);
  3286. }
  3287. catch (e) {
  3288. if (!(e instanceof NoMatch$1))
  3289. throw e;
  3290. }
  3291. }
  3292. }
  3293. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  3294. finally {
  3295. try {
  3296. if (config_1_1 && !config_1_1.done && (_a = config_1.return)) _a.call(config_1);
  3297. }
  3298. finally { if (e_1) throw e_1.error; }
  3299. }
  3300. if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
  3301. return [];
  3302. }
  3303. throw new NoMatch$1();
  3304. };
  3305. Recognizer.prototype.noLeftoversInUrl = function (segmentGroup, segments, outlet) {
  3306. return segments.length === 0 && !segmentGroup.children[outlet];
  3307. };
  3308. Recognizer.prototype.processSegmentAgainstRoute = function (route, rawSegment, segments, outlet) {
  3309. if (route.redirectTo)
  3310. throw new NoMatch$1();
  3311. if ((route.outlet || PRIMARY_OUTLET) !== outlet)
  3312. throw new NoMatch$1();
  3313. var snapshot;
  3314. var consumedSegments = [];
  3315. var rawSlicedSegments = [];
  3316. if (route.path === '**') {
  3317. var params = segments.length > 0 ? last(segments).parameters : {};
  3318. snapshot = new ActivatedRouteSnapshot(segments, params, Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, getData(route), outlet, route.component, route, getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + segments.length, getResolve(route));
  3319. }
  3320. else {
  3321. var result = match$1(rawSegment, route, segments);
  3322. consumedSegments = result.consumedSegments;
  3323. rawSlicedSegments = segments.slice(result.lastChild);
  3324. snapshot = new ActivatedRouteSnapshot(consumedSegments, result.parameters, Object.freeze(__assign({}, this.urlTree.queryParams)), this.urlTree.fragment, getData(route), outlet, route.component, route, getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + consumedSegments.length, getResolve(route));
  3325. }
  3326. var childConfig = getChildConfig(route);
  3327. var _a = split$1(rawSegment, consumedSegments, rawSlicedSegments, childConfig, this.relativeLinkResolution), segmentGroup = _a.segmentGroup, slicedSegments = _a.slicedSegments;
  3328. if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
  3329. var children_1 = this.processChildren(childConfig, segmentGroup);
  3330. return [new TreeNode(snapshot, children_1)];
  3331. }
  3332. if (childConfig.length === 0 && slicedSegments.length === 0) {
  3333. return [new TreeNode(snapshot, [])];
  3334. }
  3335. var children = this.processSegment(childConfig, segmentGroup, slicedSegments, PRIMARY_OUTLET);
  3336. return [new TreeNode(snapshot, children)];
  3337. };
  3338. return Recognizer;
  3339. }());
  3340. function sortActivatedRouteSnapshots(nodes) {
  3341. nodes.sort(function (a, b) {
  3342. if (a.value.outlet === PRIMARY_OUTLET)
  3343. return -1;
  3344. if (b.value.outlet === PRIMARY_OUTLET)
  3345. return 1;
  3346. return a.value.outlet.localeCompare(b.value.outlet);
  3347. });
  3348. }
  3349. function getChildConfig(route) {
  3350. if (route.children) {
  3351. return route.children;
  3352. }
  3353. if (route.loadChildren) {
  3354. return route._loadedConfig.routes;
  3355. }
  3356. return [];
  3357. }
  3358. function match$1(segmentGroup, route, segments) {
  3359. if (route.path === '') {
  3360. if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) {
  3361. throw new NoMatch$1();
  3362. }
  3363. return { consumedSegments: [], lastChild: 0, parameters: {} };
  3364. }
  3365. var matcher = route.matcher || defaultUrlMatcher;
  3366. var res = matcher(segments, segmentGroup, route);
  3367. if (!res)
  3368. throw new NoMatch$1();
  3369. var posParams = {};
  3370. forEach(res.posParams, function (v, k) { posParams[k] = v.path; });
  3371. var parameters = res.consumed.length > 0 ? __assign({}, posParams, res.consumed[res.consumed.length - 1].parameters) :
  3372. posParams;
  3373. return { consumedSegments: res.consumed, lastChild: res.consumed.length, parameters: parameters };
  3374. }
  3375. function checkOutletNameUniqueness(nodes) {
  3376. var names = {};
  3377. nodes.forEach(function (n) {
  3378. var routeWithSameOutletName = names[n.value.outlet];
  3379. if (routeWithSameOutletName) {
  3380. var p = routeWithSameOutletName.url.map(function (s) { return s.toString(); }).join('/');
  3381. var c = n.value.url.map(function (s) { return s.toString(); }).join('/');
  3382. throw new Error("Two segments cannot have the same outlet name: '" + p + "' and '" + c + "'.");
  3383. }
  3384. names[n.value.outlet] = n.value;
  3385. });
  3386. }
  3387. function getSourceSegmentGroup(segmentGroup) {
  3388. var s = segmentGroup;
  3389. while (s._sourceSegment) {
  3390. s = s._sourceSegment;
  3391. }
  3392. return s;
  3393. }
  3394. function getPathIndexShift(segmentGroup) {
  3395. var s = segmentGroup;
  3396. var res = (s._segmentIndexShift ? s._segmentIndexShift : 0);
  3397. while (s._sourceSegment) {
  3398. s = s._sourceSegment;
  3399. res += (s._segmentIndexShift ? s._segmentIndexShift : 0);
  3400. }
  3401. return res - 1;
  3402. }
  3403. function split$1(segmentGroup, consumedSegments, slicedSegments, config, relativeLinkResolution) {
  3404. if (slicedSegments.length > 0 &&
  3405. containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, config)) {
  3406. var s_1 = new UrlSegmentGroup(consumedSegments, createChildrenForEmptyPaths(segmentGroup, consumedSegments, config, new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
  3407. s_1._sourceSegment = segmentGroup;
  3408. s_1._segmentIndexShift = consumedSegments.length;
  3409. return { segmentGroup: s_1, slicedSegments: [] };
  3410. }
  3411. if (slicedSegments.length === 0 &&
  3412. containsEmptyPathMatches(segmentGroup, slicedSegments, config)) {
  3413. var s_2 = new UrlSegmentGroup(segmentGroup.segments, addEmptyPathsToChildrenIfNeeded(segmentGroup, consumedSegments, slicedSegments, config, segmentGroup.children, relativeLinkResolution));
  3414. s_2._sourceSegment = segmentGroup;
  3415. s_2._segmentIndexShift = consumedSegments.length;
  3416. return { segmentGroup: s_2, slicedSegments: slicedSegments };
  3417. }
  3418. var s = new UrlSegmentGroup(segmentGroup.segments, segmentGroup.children);
  3419. s._sourceSegment = segmentGroup;
  3420. s._segmentIndexShift = consumedSegments.length;
  3421. return { segmentGroup: s, slicedSegments: slicedSegments };
  3422. }
  3423. function addEmptyPathsToChildrenIfNeeded(segmentGroup, consumedSegments, slicedSegments, routes, children, relativeLinkResolution) {
  3424. var e_2, _a;
  3425. var res = {};
  3426. try {
  3427. for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
  3428. var r = routes_1_1.value;
  3429. if (emptyPathMatch(segmentGroup, slicedSegments, r) && !children[getOutlet$1(r)]) {
  3430. var s = new UrlSegmentGroup([], {});
  3431. s._sourceSegment = segmentGroup;
  3432. if (relativeLinkResolution === 'legacy') {
  3433. s._segmentIndexShift = segmentGroup.segments.length;
  3434. }
  3435. else {
  3436. s._segmentIndexShift = consumedSegments.length;
  3437. }
  3438. res[getOutlet$1(r)] = s;
  3439. }
  3440. }
  3441. }
  3442. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  3443. finally {
  3444. try {
  3445. if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
  3446. }
  3447. finally { if (e_2) throw e_2.error; }
  3448. }
  3449. return __assign({}, children, res);
  3450. }
  3451. function createChildrenForEmptyPaths(segmentGroup, consumedSegments, routes, primarySegment) {
  3452. var e_3, _a;
  3453. var res = {};
  3454. res[PRIMARY_OUTLET] = primarySegment;
  3455. primarySegment._sourceSegment = segmentGroup;
  3456. primarySegment._segmentIndexShift = consumedSegments.length;
  3457. try {
  3458. for (var routes_2 = __values(routes), routes_2_1 = routes_2.next(); !routes_2_1.done; routes_2_1 = routes_2.next()) {
  3459. var r = routes_2_1.value;
  3460. if (r.path === '' && getOutlet$1(r) !== PRIMARY_OUTLET) {
  3461. var s = new UrlSegmentGroup([], {});
  3462. s._sourceSegment = segmentGroup;
  3463. s._segmentIndexShift = consumedSegments.length;
  3464. res[getOutlet$1(r)] = s;
  3465. }
  3466. }
  3467. }
  3468. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  3469. finally {
  3470. try {
  3471. if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
  3472. }
  3473. finally { if (e_3) throw e_3.error; }
  3474. }
  3475. return res;
  3476. }
  3477. function containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, routes) {
  3478. return routes.some(function (r) { return emptyPathMatch(segmentGroup, slicedSegments, r) && getOutlet$1(r) !== PRIMARY_OUTLET; });
  3479. }
  3480. function containsEmptyPathMatches(segmentGroup, slicedSegments, routes) {
  3481. return routes.some(function (r) { return emptyPathMatch(segmentGroup, slicedSegments, r); });
  3482. }
  3483. function emptyPathMatch(segmentGroup, slicedSegments, r) {
  3484. if ((segmentGroup.hasChildren() || slicedSegments.length > 0) && r.pathMatch === 'full') {
  3485. return false;
  3486. }
  3487. return r.path === '' && r.redirectTo === undefined;
  3488. }
  3489. function getOutlet$1(route) {
  3490. return route.outlet || PRIMARY_OUTLET;
  3491. }
  3492. function getData(route) {
  3493. return route.data || {};
  3494. }
  3495. function getResolve(route) {
  3496. return route.resolve || {};
  3497. }
  3498. /**
  3499. * @license
  3500. * Copyright Google Inc. All Rights Reserved.
  3501. *
  3502. * Use of this source code is governed by an MIT-style license that can be
  3503. * found in the LICENSE file at https://angular.io/license
  3504. */
  3505. function recognize$1(rootComponentType, config, serializer, paramsInheritanceStrategy, relativeLinkResolution) {
  3506. return function (source) {
  3507. return source.pipe(operators.mergeMap(function (t) { return recognize(rootComponentType, config, t.urlAfterRedirects, serializer(t.urlAfterRedirects), paramsInheritanceStrategy, relativeLinkResolution)
  3508. .pipe(operators.map(function (targetSnapshot) { return (__assign({}, t, { targetSnapshot: targetSnapshot })); })); }));
  3509. };
  3510. }
  3511. /**
  3512. * @license
  3513. * Copyright Google Inc. All Rights Reserved.
  3514. *
  3515. * Use of this source code is governed by an MIT-style license that can be
  3516. * found in the LICENSE file at https://angular.io/license
  3517. */
  3518. function resolveData(paramsInheritanceStrategy, moduleInjector) {
  3519. return function (source) {
  3520. return source.pipe(operators.mergeMap(function (t) {
  3521. var targetSnapshot = t.targetSnapshot, canActivateChecks = t.guards.canActivateChecks;
  3522. if (!canActivateChecks.length) {
  3523. return rxjs.of(t);
  3524. }
  3525. return rxjs.from(canActivateChecks)
  3526. .pipe(operators.concatMap(function (check) { return runResolve(check.route, targetSnapshot, paramsInheritanceStrategy, moduleInjector); }), operators.reduce(function (_, __) { return _; }), operators.map(function (_) { return t; }));
  3527. }));
  3528. };
  3529. }
  3530. function runResolve(futureARS, futureRSS, paramsInheritanceStrategy, moduleInjector) {
  3531. var resolve = futureARS._resolve;
  3532. return resolveNode(resolve, futureARS, futureRSS, moduleInjector)
  3533. .pipe(operators.map(function (resolvedData) {
  3534. futureARS._resolvedData = resolvedData;
  3535. futureARS.data = __assign({}, futureARS.data, inheritedParamsDataResolve(futureARS, paramsInheritanceStrategy).resolve);
  3536. return null;
  3537. }));
  3538. }
  3539. function resolveNode(resolve, futureARS, futureRSS, moduleInjector) {
  3540. var keys = Object.keys(resolve);
  3541. if (keys.length === 0) {
  3542. return rxjs.of({});
  3543. }
  3544. if (keys.length === 1) {
  3545. var key_1 = keys[0];
  3546. return getResolver(resolve[key_1], futureARS, futureRSS, moduleInjector)
  3547. .pipe(operators.map(function (value) {
  3548. var _a;
  3549. return _a = {}, _a[key_1] = value, _a;
  3550. }));
  3551. }
  3552. var data = {};
  3553. var runningResolvers$ = rxjs.from(keys).pipe(operators.mergeMap(function (key) {
  3554. return getResolver(resolve[key], futureARS, futureRSS, moduleInjector)
  3555. .pipe(operators.map(function (value) {
  3556. data[key] = value;
  3557. return value;
  3558. }));
  3559. }));
  3560. return runningResolvers$.pipe(operators.last(), operators.map(function () { return data; }));
  3561. }
  3562. function getResolver(injectionToken, futureARS, futureRSS, moduleInjector) {
  3563. var resolver = getToken(injectionToken, futureARS, moduleInjector);
  3564. return resolver.resolve ? wrapIntoObservable(resolver.resolve(futureARS, futureRSS)) :
  3565. wrapIntoObservable(resolver(futureARS, futureRSS));
  3566. }
  3567. /**
  3568. * @license
  3569. * Copyright Google Inc. All Rights Reserved.
  3570. *
  3571. * Use of this source code is governed by an MIT-style license that can be
  3572. * found in the LICENSE file at https://angular.io/license
  3573. */
  3574. /**
  3575. * Perform a side effect through a switchMap for every emission on the source Observable,
  3576. * but return an Observable that is identical to the source. It's essentially the same as
  3577. * the `tap` operator, but if the side effectful `next` function returns an ObservableInput,
  3578. * it will wait before continuing with the original value.
  3579. */
  3580. function switchTap(next) {
  3581. return function (source) {
  3582. return source.pipe(operators.switchMap(function (v) {
  3583. var nextResult = next(v);
  3584. if (nextResult) {
  3585. return rxjs.from(nextResult).pipe(operators.map(function () { return v; }));
  3586. }
  3587. return rxjs.from([v]);
  3588. }));
  3589. };
  3590. }
  3591. /**
  3592. * @license
  3593. * Copyright Google Inc. All Rights Reserved.
  3594. *
  3595. * Use of this source code is governed by an MIT-style license that can be
  3596. * found in the LICENSE file at https://angular.io/license
  3597. */
  3598. /**
  3599. * @description
  3600. *
  3601. * Provides a way to customize when activated routes get reused.
  3602. *
  3603. * @publicApi
  3604. */
  3605. var RouteReuseStrategy = /** @class */ (function () {
  3606. function RouteReuseStrategy() {
  3607. }
  3608. return RouteReuseStrategy;
  3609. }());
  3610. /**
  3611. * Does not detach any subtrees. Reuses routes as long as their route config is the same.
  3612. */
  3613. var DefaultRouteReuseStrategy = /** @class */ (function () {
  3614. function DefaultRouteReuseStrategy() {
  3615. }
  3616. DefaultRouteReuseStrategy.prototype.shouldDetach = function (route) { return false; };
  3617. DefaultRouteReuseStrategy.prototype.store = function (route, detachedTree) { };
  3618. DefaultRouteReuseStrategy.prototype.shouldAttach = function (route) { return false; };
  3619. DefaultRouteReuseStrategy.prototype.retrieve = function (route) { return null; };
  3620. DefaultRouteReuseStrategy.prototype.shouldReuseRoute = function (future, curr) {
  3621. return future.routeConfig === curr.routeConfig;
  3622. };
  3623. return DefaultRouteReuseStrategy;
  3624. }());
  3625. /**
  3626. * @license
  3627. * Copyright Google Inc. All Rights Reserved.
  3628. *
  3629. * Use of this source code is governed by an MIT-style license that can be
  3630. * found in the LICENSE file at https://angular.io/license
  3631. */
  3632. /**
  3633. * @docsNotRequired
  3634. * @publicApi
  3635. */
  3636. var ROUTES = new core.InjectionToken('ROUTES');
  3637. var RouterConfigLoader = /** @class */ (function () {
  3638. function RouterConfigLoader(loader, compiler, onLoadStartListener, onLoadEndListener) {
  3639. this.loader = loader;
  3640. this.compiler = compiler;
  3641. this.onLoadStartListener = onLoadStartListener;
  3642. this.onLoadEndListener = onLoadEndListener;
  3643. }
  3644. RouterConfigLoader.prototype.load = function (parentInjector, route) {
  3645. var _this = this;
  3646. if (this.onLoadStartListener) {
  3647. this.onLoadStartListener(route);
  3648. }
  3649. var moduleFactory$ = this.loadModuleFactory(route.loadChildren);
  3650. return moduleFactory$.pipe(operators.map(function (factory) {
  3651. if (_this.onLoadEndListener) {
  3652. _this.onLoadEndListener(route);
  3653. }
  3654. var module = factory.create(parentInjector);
  3655. return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)).map(standardizeConfig), module);
  3656. }));
  3657. };
  3658. RouterConfigLoader.prototype.loadModuleFactory = function (loadChildren) {
  3659. var _this = this;
  3660. if (typeof loadChildren === 'string') {
  3661. return rxjs.from(this.loader.load(loadChildren));
  3662. }
  3663. else {
  3664. return wrapIntoObservable(loadChildren()).pipe(operators.mergeMap(function (t) {
  3665. if (t instanceof core.NgModuleFactory) {
  3666. return rxjs.of(t);
  3667. }
  3668. else {
  3669. return rxjs.from(_this.compiler.compileModuleAsync(t));
  3670. }
  3671. }));
  3672. }
  3673. };
  3674. return RouterConfigLoader;
  3675. }());
  3676. /**
  3677. * @license
  3678. * Copyright Google Inc. All Rights Reserved.
  3679. *
  3680. * Use of this source code is governed by an MIT-style license that can be
  3681. * found in the LICENSE file at https://angular.io/license
  3682. */
  3683. /**
  3684. * @description
  3685. *
  3686. * Provides a way to migrate AngularJS applications to Angular.
  3687. *
  3688. * @publicApi
  3689. */
  3690. var UrlHandlingStrategy = /** @class */ (function () {
  3691. function UrlHandlingStrategy() {
  3692. }
  3693. return UrlHandlingStrategy;
  3694. }());
  3695. /**
  3696. * @publicApi
  3697. */
  3698. var DefaultUrlHandlingStrategy = /** @class */ (function () {
  3699. function DefaultUrlHandlingStrategy() {
  3700. }
  3701. DefaultUrlHandlingStrategy.prototype.shouldProcessUrl = function (url) { return true; };
  3702. DefaultUrlHandlingStrategy.prototype.extract = function (url) { return url; };
  3703. DefaultUrlHandlingStrategy.prototype.merge = function (newUrlPart, wholeUrl) { return newUrlPart; };
  3704. return DefaultUrlHandlingStrategy;
  3705. }());
  3706. /**
  3707. * @license
  3708. * Copyright Google Inc. All Rights Reserved.
  3709. *
  3710. * Use of this source code is governed by an MIT-style license that can be
  3711. * found in the LICENSE file at https://angular.io/license
  3712. */
  3713. function defaultErrorHandler(error) {
  3714. throw error;
  3715. }
  3716. function defaultMalformedUriErrorHandler(error, urlSerializer, url) {
  3717. return urlSerializer.parse('/');
  3718. }
  3719. /**
  3720. * @internal
  3721. */
  3722. function defaultRouterHook(snapshot, runExtras) {
  3723. return rxjs.of(null);
  3724. }
  3725. /**
  3726. * @description
  3727. *
  3728. * An NgModule that provides navigation and URL manipulation capabilities.
  3729. *
  3730. * @see `Route`.
  3731. * @see [Routing and Navigation Guide](guide/router).
  3732. *
  3733. * @ngModule RouterModule
  3734. *
  3735. * @publicApi
  3736. */
  3737. var Router = /** @class */ (function () {
  3738. /**
  3739. * Creates the router service.
  3740. */
  3741. // TODO: vsavkin make internal after the final is out.
  3742. function Router(rootComponentType, urlSerializer, rootContexts, location, injector, loader, compiler, config) {
  3743. var _this = this;
  3744. this.rootComponentType = rootComponentType;
  3745. this.urlSerializer = urlSerializer;
  3746. this.rootContexts = rootContexts;
  3747. this.location = location;
  3748. this.config = config;
  3749. this.lastSuccessfulNavigation = null;
  3750. this.currentNavigation = null;
  3751. this.navigationId = 0;
  3752. this.isNgZoneEnabled = false;
  3753. /**
  3754. * An event stream for routing events in this NgModule.
  3755. */
  3756. this.events = new rxjs.Subject();
  3757. /**
  3758. * A handler for navigation errors in this NgModule.
  3759. */
  3760. this.errorHandler = defaultErrorHandler;
  3761. /**
  3762. * Malformed uri error handler is invoked when `Router.parseUrl(url)` throws an
  3763. * error due to containing an invalid character. The most common case would be a `%` sign
  3764. * that's not encoded and is not part of a percent encoded sequence.
  3765. */
  3766. this.malformedUriErrorHandler = defaultMalformedUriErrorHandler;
  3767. /**
  3768. * True if at least one navigation event has occurred,
  3769. * false otherwise.
  3770. */
  3771. this.navigated = false;
  3772. this.lastSuccessfulId = -1;
  3773. /**
  3774. * Hooks that enable you to pause navigation,
  3775. * either before or after the preactivation phase.
  3776. * Used by `RouterModule`.
  3777. *
  3778. * @internal
  3779. */
  3780. this.hooks = {
  3781. beforePreactivation: defaultRouterHook,
  3782. afterPreactivation: defaultRouterHook
  3783. };
  3784. /**
  3785. * Extracts and merges URLs. Used for AngularJS to Angular migrations.
  3786. */
  3787. this.urlHandlingStrategy = new DefaultUrlHandlingStrategy();
  3788. /**
  3789. * The strategy for re-using routes.
  3790. */
  3791. this.routeReuseStrategy = new DefaultRouteReuseStrategy();
  3792. /**
  3793. * How to handle a navigation request to the current URL. One of:
  3794. * - `'ignore'` : The router ignores the request.
  3795. * - `'reload'` : The router reloads the URL. Use to implement a "refresh" feature.
  3796. */
  3797. this.onSameUrlNavigation = 'ignore';
  3798. /**
  3799. * How to merge parameters, data, and resolved data from parent to child
  3800. * routes. One of:
  3801. *
  3802. * - `'emptyOnly'` : Inherit parent parameters, data, and resolved data
  3803. * for path-less or component-less routes.
  3804. * - `'always'` : Inherit parent parameters, data, and resolved data
  3805. * for all child routes.
  3806. */
  3807. this.paramsInheritanceStrategy = 'emptyOnly';
  3808. /**
  3809. * Defines when the router updates the browser URL. The default behavior is to update after
  3810. * successful navigation. However, some applications may prefer a mode where the URL gets
  3811. * updated at the beginning of navigation. The most common use case would be updating the
  3812. * URL early so if navigation fails, you can show an error message with the URL that failed.
  3813. * Available options are:
  3814. *
  3815. * - `'deferred'`, the default, updates the browser URL after navigation has finished.
  3816. * - `'eager'`, updates browser URL at the beginning of navigation.
  3817. */
  3818. this.urlUpdateStrategy = 'deferred';
  3819. /**
  3820. * See {@link RouterModule} for more information.
  3821. */
  3822. this.relativeLinkResolution = 'legacy';
  3823. var onLoadStart = function (r) { return _this.triggerEvent(new RouteConfigLoadStart(r)); };
  3824. var onLoadEnd = function (r) { return _this.triggerEvent(new RouteConfigLoadEnd(r)); };
  3825. this.ngModule = injector.get(core.NgModuleRef);
  3826. this.console = injector.get(core.ɵConsole);
  3827. var ngZone = injector.get(core.NgZone);
  3828. this.isNgZoneEnabled = ngZone instanceof core.NgZone;
  3829. this.resetConfig(config);
  3830. this.currentUrlTree = createEmptyUrlTree();
  3831. this.rawUrlTree = this.currentUrlTree;
  3832. this.browserUrlTree = this.currentUrlTree;
  3833. this.configLoader = new RouterConfigLoader(loader, compiler, onLoadStart, onLoadEnd);
  3834. this.routerState = createEmptyState(this.currentUrlTree, this.rootComponentType);
  3835. this.transitions = new rxjs.BehaviorSubject({
  3836. id: 0,
  3837. currentUrlTree: this.currentUrlTree,
  3838. currentRawUrl: this.currentUrlTree,
  3839. extractedUrl: this.urlHandlingStrategy.extract(this.currentUrlTree),
  3840. urlAfterRedirects: this.urlHandlingStrategy.extract(this.currentUrlTree),
  3841. rawUrl: this.currentUrlTree,
  3842. extras: {},
  3843. resolve: null,
  3844. reject: null,
  3845. promise: Promise.resolve(true),
  3846. source: 'imperative',
  3847. restoredState: null,
  3848. currentSnapshot: this.routerState.snapshot,
  3849. targetSnapshot: null,
  3850. currentRouterState: this.routerState,
  3851. targetRouterState: null,
  3852. guards: { canActivateChecks: [], canDeactivateChecks: [] },
  3853. guardsResult: null,
  3854. });
  3855. this.navigations = this.setupNavigations(this.transitions);
  3856. this.processNavigations();
  3857. }
  3858. Router.prototype.setupNavigations = function (transitions) {
  3859. var _this = this;
  3860. var eventsSubject = this.events;
  3861. return transitions.pipe(operators.filter(function (t) { return t.id !== 0; }),
  3862. // Extract URL
  3863. operators.map(function (t) { return (__assign({}, t, { extractedUrl: _this.urlHandlingStrategy.extract(t.rawUrl) })); }),
  3864. // Using switchMap so we cancel executing navigations when a new one comes in
  3865. operators.switchMap(function (t) {
  3866. var completed = false;
  3867. var errored = false;
  3868. return rxjs.of(t).pipe(
  3869. // Store the Navigation object
  3870. operators.tap(function (t) {
  3871. _this.currentNavigation = {
  3872. id: t.id,
  3873. initialUrl: t.currentRawUrl,
  3874. extractedUrl: t.extractedUrl,
  3875. trigger: t.source,
  3876. extras: t.extras,
  3877. previousNavigation: _this.lastSuccessfulNavigation ? __assign({}, _this.lastSuccessfulNavigation, { previousNavigation: null }) :
  3878. null
  3879. };
  3880. }), operators.switchMap(function (t) {
  3881. var urlTransition = !_this.navigated || t.extractedUrl.toString() !== _this.browserUrlTree.toString();
  3882. var processCurrentUrl = (_this.onSameUrlNavigation === 'reload' ? true : urlTransition) &&
  3883. _this.urlHandlingStrategy.shouldProcessUrl(t.rawUrl);
  3884. if (processCurrentUrl) {
  3885. return rxjs.of(t).pipe(
  3886. // Fire NavigationStart event
  3887. operators.switchMap(function (t) {
  3888. var transition = _this.transitions.getValue();
  3889. eventsSubject.next(new NavigationStart(t.id, _this.serializeUrl(t.extractedUrl), t.source, t.restoredState));
  3890. if (transition !== _this.transitions.getValue()) {
  3891. return rxjs.EMPTY;
  3892. }
  3893. return [t];
  3894. }),
  3895. // This delay is required to match old behavior that forced navigation to
  3896. // always be async
  3897. operators.switchMap(function (t) { return Promise.resolve(t); }),
  3898. // ApplyRedirects
  3899. applyRedirects$1(_this.ngModule.injector, _this.configLoader, _this.urlSerializer, _this.config),
  3900. // Update the currentNavigation
  3901. operators.tap(function (t) {
  3902. _this.currentNavigation = __assign({}, _this.currentNavigation, { finalUrl: t.urlAfterRedirects });
  3903. }),
  3904. // Recognize
  3905. recognize$1(_this.rootComponentType, _this.config, function (url) { return _this.serializeUrl(url); }, _this.paramsInheritanceStrategy, _this.relativeLinkResolution),
  3906. // Update URL if in `eager` update mode
  3907. operators.tap(function (t) {
  3908. if (_this.urlUpdateStrategy === 'eager') {
  3909. if (!t.extras.skipLocationChange) {
  3910. _this.setBrowserUrl(t.urlAfterRedirects, !!t.extras.replaceUrl, t.id, t.extras.state);
  3911. }
  3912. _this.browserUrlTree = t.urlAfterRedirects;
  3913. }
  3914. }),
  3915. // Fire RoutesRecognized
  3916. operators.tap(function (t) {
  3917. var routesRecognized = new RoutesRecognized(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
  3918. eventsSubject.next(routesRecognized);
  3919. }));
  3920. }
  3921. else {
  3922. var processPreviousUrl = urlTransition && _this.rawUrlTree &&
  3923. _this.urlHandlingStrategy.shouldProcessUrl(_this.rawUrlTree);
  3924. /* When the current URL shouldn't be processed, but the previous one was, we
  3925. * handle this "error condition" by navigating to the previously successful URL,
  3926. * but leaving the URL intact.*/
  3927. if (processPreviousUrl) {
  3928. var id = t.id, extractedUrl = t.extractedUrl, source = t.source, restoredState = t.restoredState, extras = t.extras;
  3929. var navStart = new NavigationStart(id, _this.serializeUrl(extractedUrl), source, restoredState);
  3930. eventsSubject.next(navStart);
  3931. var targetSnapshot = createEmptyState(extractedUrl, _this.rootComponentType).snapshot;
  3932. return rxjs.of(__assign({}, t, { targetSnapshot: targetSnapshot, urlAfterRedirects: extractedUrl, extras: __assign({}, extras, { skipLocationChange: false, replaceUrl: false }) }));
  3933. }
  3934. else {
  3935. /* When neither the current or previous URL can be processed, do nothing other
  3936. * than update router's internal reference to the current "settled" URL. This
  3937. * way the next navigation will be coming from the current URL in the browser.
  3938. */
  3939. _this.rawUrlTree = t.rawUrl;
  3940. _this.browserUrlTree = t.urlAfterRedirects;
  3941. t.resolve(null);
  3942. return rxjs.EMPTY;
  3943. }
  3944. }
  3945. }),
  3946. // Before Preactivation
  3947. switchTap(function (t) {
  3948. var targetSnapshot = t.targetSnapshot, navigationId = t.id, appliedUrlTree = t.extractedUrl, rawUrlTree = t.rawUrl, _a = t.extras, skipLocationChange = _a.skipLocationChange, replaceUrl = _a.replaceUrl;
  3949. return _this.hooks.beforePreactivation(targetSnapshot, {
  3950. navigationId: navigationId,
  3951. appliedUrlTree: appliedUrlTree,
  3952. rawUrlTree: rawUrlTree,
  3953. skipLocationChange: !!skipLocationChange,
  3954. replaceUrl: !!replaceUrl,
  3955. });
  3956. }),
  3957. // --- GUARDS ---
  3958. operators.tap(function (t) {
  3959. var guardsStart = new GuardsCheckStart(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
  3960. _this.triggerEvent(guardsStart);
  3961. }), operators.map(function (t) { return (__assign({}, t, { guards: getAllRouteGuards(t.targetSnapshot, t.currentSnapshot, _this.rootContexts) })); }), checkGuards(_this.ngModule.injector, function (evt) { return _this.triggerEvent(evt); }), operators.tap(function (t) {
  3962. if (isUrlTree(t.guardsResult)) {
  3963. var error = navigationCancelingError("Redirecting to \"" + _this.serializeUrl(t.guardsResult) + "\"");
  3964. error.url = t.guardsResult;
  3965. throw error;
  3966. }
  3967. }), operators.tap(function (t) {
  3968. var guardsEnd = new GuardsCheckEnd(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot, !!t.guardsResult);
  3969. _this.triggerEvent(guardsEnd);
  3970. }), operators.filter(function (t) {
  3971. if (!t.guardsResult) {
  3972. _this.resetUrlToCurrentUrlTree();
  3973. var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), '');
  3974. eventsSubject.next(navCancel);
  3975. t.resolve(false);
  3976. return false;
  3977. }
  3978. return true;
  3979. }),
  3980. // --- RESOLVE ---
  3981. switchTap(function (t) {
  3982. if (t.guards.canActivateChecks.length) {
  3983. return rxjs.of(t).pipe(operators.tap(function (t) {
  3984. var resolveStart = new ResolveStart(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
  3985. _this.triggerEvent(resolveStart);
  3986. }), resolveData(_this.paramsInheritanceStrategy, _this.ngModule.injector), //
  3987. operators.tap(function (t) {
  3988. var resolveEnd = new ResolveEnd(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(t.urlAfterRedirects), t.targetSnapshot);
  3989. _this.triggerEvent(resolveEnd);
  3990. }));
  3991. }
  3992. return undefined;
  3993. }),
  3994. // --- AFTER PREACTIVATION ---
  3995. switchTap(function (t) {
  3996. var targetSnapshot = t.targetSnapshot, navigationId = t.id, appliedUrlTree = t.extractedUrl, rawUrlTree = t.rawUrl, _a = t.extras, skipLocationChange = _a.skipLocationChange, replaceUrl = _a.replaceUrl;
  3997. return _this.hooks.afterPreactivation(targetSnapshot, {
  3998. navigationId: navigationId,
  3999. appliedUrlTree: appliedUrlTree,
  4000. rawUrlTree: rawUrlTree,
  4001. skipLocationChange: !!skipLocationChange,
  4002. replaceUrl: !!replaceUrl,
  4003. });
  4004. }), operators.map(function (t) {
  4005. var targetRouterState = createRouterState(_this.routeReuseStrategy, t.targetSnapshot, t.currentRouterState);
  4006. return (__assign({}, t, { targetRouterState: targetRouterState }));
  4007. }),
  4008. /* Once here, we are about to activate syncronously. The assumption is this will
  4009. succeed, and user code may read from the Router service. Therefore before
  4010. activation, we need to update router properties storing the current URL and the
  4011. RouterState, as well as updated the browser URL. All this should happen *before*
  4012. activating. */
  4013. operators.tap(function (t) {
  4014. _this.currentUrlTree = t.urlAfterRedirects;
  4015. _this.rawUrlTree = _this.urlHandlingStrategy.merge(_this.currentUrlTree, t.rawUrl);
  4016. _this.routerState = t.targetRouterState;
  4017. if (_this.urlUpdateStrategy === 'deferred') {
  4018. if (!t.extras.skipLocationChange) {
  4019. _this.setBrowserUrl(_this.rawUrlTree, !!t.extras.replaceUrl, t.id, t.extras.state);
  4020. }
  4021. _this.browserUrlTree = t.urlAfterRedirects;
  4022. }
  4023. }), activateRoutes(_this.rootContexts, _this.routeReuseStrategy, function (evt) { return _this.triggerEvent(evt); }), operators.tap({ next: function () { completed = true; }, complete: function () { completed = true; } }), operators.finalize(function () {
  4024. /* When the navigation stream finishes either through error or success, we set the
  4025. * `completed` or `errored` flag. However, there are some situations where we could
  4026. * get here without either of those being set. For instance, a redirect during
  4027. * NavigationStart. Therefore, this is a catch-all to make sure the NavigationCancel
  4028. * event is fired when a navigation gets cancelled but not caught by other means. */
  4029. if (!completed && !errored) {
  4030. // Must reset to current URL tree here to ensure history.state is set. On a fresh
  4031. // page load, if a new navigation comes in before a successful navigation
  4032. // completes, there will be nothing in history.state.navigationId. This can cause
  4033. // sync problems with AngularJS sync code which looks for a value here in order
  4034. // to determine whether or not to handle a given popstate event or to leave it
  4035. // to the Angualr router.
  4036. _this.resetUrlToCurrentUrlTree();
  4037. var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), "Navigation ID " + t.id + " is not equal to the current navigation id " + _this.navigationId);
  4038. eventsSubject.next(navCancel);
  4039. t.resolve(false);
  4040. }
  4041. // currentNavigation should always be reset to null here. If navigation was
  4042. // successful, lastSuccessfulTransition will have already been set. Therefore we
  4043. // can safely set currentNavigation to null here.
  4044. _this.currentNavigation = null;
  4045. }), operators.catchError(function (e) {
  4046. errored = true;
  4047. /* This error type is issued during Redirect, and is handled as a cancellation
  4048. * rather than an error. */
  4049. if (isNavigationCancelingError(e)) {
  4050. var redirecting = isUrlTree(e.url);
  4051. if (!redirecting) {
  4052. // Set property only if we're not redirecting. If we landed on a page and
  4053. // redirect to `/` route, the new navigation is going to see the `/` isn't
  4054. // a change from the default currentUrlTree and won't navigate. This is
  4055. // only applicable with initial navigation, so setting `navigated` only when
  4056. // not redirecting resolves this scenario.
  4057. _this.navigated = true;
  4058. _this.resetStateAndUrl(t.currentRouterState, t.currentUrlTree, t.rawUrl);
  4059. }
  4060. var navCancel = new NavigationCancel(t.id, _this.serializeUrl(t.extractedUrl), e.message);
  4061. eventsSubject.next(navCancel);
  4062. t.resolve(false);
  4063. if (redirecting) {
  4064. _this.navigateByUrl(e.url);
  4065. }
  4066. /* All other errors should reset to the router's internal URL reference to the
  4067. * pre-error state. */
  4068. }
  4069. else {
  4070. _this.resetStateAndUrl(t.currentRouterState, t.currentUrlTree, t.rawUrl);
  4071. var navError = new NavigationError(t.id, _this.serializeUrl(t.extractedUrl), e);
  4072. eventsSubject.next(navError);
  4073. try {
  4074. t.resolve(_this.errorHandler(e));
  4075. }
  4076. catch (ee) {
  4077. t.reject(ee);
  4078. }
  4079. }
  4080. return rxjs.EMPTY;
  4081. }));
  4082. // TODO(jasonaden): remove cast once g3 is on updated TypeScript
  4083. }));
  4084. };
  4085. /**
  4086. * @internal
  4087. * TODO: this should be removed once the constructor of the router made internal
  4088. */
  4089. Router.prototype.resetRootComponentType = function (rootComponentType) {
  4090. this.rootComponentType = rootComponentType;
  4091. // TODO: vsavkin router 4.0 should make the root component set to null
  4092. // this will simplify the lifecycle of the router.
  4093. this.routerState.root.component = this.rootComponentType;
  4094. };
  4095. Router.prototype.getTransition = function () {
  4096. var transition = this.transitions.value;
  4097. // This value needs to be set. Other values such as extractedUrl are set on initial navigation
  4098. // but the urlAfterRedirects may not get set if we aren't processing the new URL *and* not
  4099. // processing the previous URL.
  4100. transition.urlAfterRedirects = this.browserUrlTree;
  4101. return transition;
  4102. };
  4103. Router.prototype.setTransition = function (t) {
  4104. this.transitions.next(__assign({}, this.getTransition(), t));
  4105. };
  4106. /**
  4107. * Sets up the location change listener and performs the initial navigation.
  4108. */
  4109. Router.prototype.initialNavigation = function () {
  4110. this.setUpLocationChangeListener();
  4111. if (this.navigationId === 0) {
  4112. this.navigateByUrl(this.location.path(true), { replaceUrl: true });
  4113. }
  4114. };
  4115. /**
  4116. * Sets up the location change listener.
  4117. */
  4118. Router.prototype.setUpLocationChangeListener = function () {
  4119. var _this = this;
  4120. // Don't need to use Zone.wrap any more, because zone.js
  4121. // already patch onPopState, so location change callback will
  4122. // run into ngZone
  4123. if (!this.locationSubscription) {
  4124. this.locationSubscription = this.location.subscribe(function (change) {
  4125. var rawUrlTree = _this.parseUrl(change['url']);
  4126. var source = change['type'] === 'popstate' ? 'popstate' : 'hashchange';
  4127. // Navigations coming from Angular router have a navigationId state property. When this
  4128. // exists, restore the state.
  4129. var state = change.state && change.state.navigationId ? change.state : null;
  4130. setTimeout(function () { _this.scheduleNavigation(rawUrlTree, source, state, { replaceUrl: true }); }, 0);
  4131. });
  4132. }
  4133. };
  4134. Object.defineProperty(Router.prototype, "url", {
  4135. /** The current URL. */
  4136. get: function () { return this.serializeUrl(this.currentUrlTree); },
  4137. enumerable: true,
  4138. configurable: true
  4139. });
  4140. /** The current Navigation object if one exists */
  4141. Router.prototype.getCurrentNavigation = function () { return this.currentNavigation; };
  4142. /** @internal */
  4143. Router.prototype.triggerEvent = function (event) { this.events.next(event); };
  4144. /**
  4145. * Resets the configuration used for navigation and generating links.
  4146. *
  4147. * @param config The route array for the new configuration.
  4148. *
  4149. * @usageNotes
  4150. *
  4151. * ```
  4152. * router.resetConfig([
  4153. * { path: 'team/:id', component: TeamCmp, children: [
  4154. * { path: 'simple', component: SimpleCmp },
  4155. * { path: 'user/:name', component: UserCmp }
  4156. * ]}
  4157. * ]);
  4158. * ```
  4159. */
  4160. Router.prototype.resetConfig = function (config) {
  4161. validateConfig(config);
  4162. this.config = config.map(standardizeConfig);
  4163. this.navigated = false;
  4164. this.lastSuccessfulId = -1;
  4165. };
  4166. /** @docsNotRequired */
  4167. Router.prototype.ngOnDestroy = function () { this.dispose(); };
  4168. /** Disposes of the router. */
  4169. Router.prototype.dispose = function () {
  4170. if (this.locationSubscription) {
  4171. this.locationSubscription.unsubscribe();
  4172. this.locationSubscription = null;
  4173. }
  4174. };
  4175. /**
  4176. * Applies an array of commands to the current URL tree and creates a new URL tree.
  4177. *
  4178. * When given an activate route, applies the given commands starting from the route.
  4179. * When not given a route, applies the given command starting from the root.
  4180. *
  4181. * @param commands An array of commands to apply.
  4182. * @param navigationExtras
  4183. * @returns The new URL tree.
  4184. *
  4185. * @usageNotes
  4186. *
  4187. * ```
  4188. * // create /team/33/user/11
  4189. * router.createUrlTree(['/team', 33, 'user', 11]);
  4190. *
  4191. * // create /team/33;expand=true/user/11
  4192. * router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
  4193. *
  4194. * // you can collapse static segments like this (this works only with the first passed-in value):
  4195. * router.createUrlTree(['/team/33/user', userId]);
  4196. *
  4197. * // If the first segment can contain slashes, and you do not want the router to split it, you
  4198. * // can do the following:
  4199. *
  4200. * router.createUrlTree([{segmentPath: '/one/two'}]);
  4201. *
  4202. * // create /team/33/(user/11//right:chat)
  4203. * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: 'chat'}}]);
  4204. *
  4205. * // remove the right secondary node
  4206. * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: null}}]);
  4207. *
  4208. * // assuming the current url is `/team/33/user/11` and the route points to `user/11`
  4209. *
  4210. * // navigate to /team/33/user/11/details
  4211. * router.createUrlTree(['details'], {relativeTo: route});
  4212. *
  4213. * // navigate to /team/33/user/22
  4214. * router.createUrlTree(['../22'], {relativeTo: route});
  4215. *
  4216. * // navigate to /team/44/user/22
  4217. * router.createUrlTree(['../../team/44/user/22'], {relativeTo: route});
  4218. * ```
  4219. */
  4220. Router.prototype.createUrlTree = function (commands, navigationExtras) {
  4221. if (navigationExtras === void 0) { navigationExtras = {}; }
  4222. var relativeTo = navigationExtras.relativeTo, queryParams = navigationExtras.queryParams, fragment = navigationExtras.fragment, preserveQueryParams = navigationExtras.preserveQueryParams, queryParamsHandling = navigationExtras.queryParamsHandling, preserveFragment = navigationExtras.preserveFragment;
  4223. if (core.isDevMode() && preserveQueryParams && console && console.warn) {
  4224. console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
  4225. }
  4226. var a = relativeTo || this.routerState.root;
  4227. var f = preserveFragment ? this.currentUrlTree.fragment : fragment;
  4228. var q = null;
  4229. if (queryParamsHandling) {
  4230. switch (queryParamsHandling) {
  4231. case 'merge':
  4232. q = __assign({}, this.currentUrlTree.queryParams, queryParams);
  4233. break;
  4234. case 'preserve':
  4235. q = this.currentUrlTree.queryParams;
  4236. break;
  4237. default:
  4238. q = queryParams || null;
  4239. }
  4240. }
  4241. else {
  4242. q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null;
  4243. }
  4244. if (q !== null) {
  4245. q = this.removeEmptyProps(q);
  4246. }
  4247. return createUrlTree(a, this.currentUrlTree, commands, q, f);
  4248. };
  4249. /**
  4250. * Navigate based on the provided URL, which must be absolute.
  4251. *
  4252. * @param url An absolute URL. The function does not apply any delta to the current URL.
  4253. * @param extras An object containing properties that modify the navigation strategy.
  4254. * The function ignores any properties in the `NavigationExtras` that would change the
  4255. * provided URL.
  4256. *
  4257. * @returns A Promise that resolves to 'true' when navigation succeeds,
  4258. * to 'false' when navigation fails, or is rejected on error.
  4259. *
  4260. * @usageNotes
  4261. *
  4262. * ### Example
  4263. *
  4264. * ```
  4265. * router.navigateByUrl("/team/33/user/11");
  4266. *
  4267. * // Navigate without updating the URL
  4268. * router.navigateByUrl("/team/33/user/11", { skipLocationChange: true });
  4269. * ```
  4270. *
  4271. */
  4272. Router.prototype.navigateByUrl = function (url, extras) {
  4273. if (extras === void 0) { extras = { skipLocationChange: false }; }
  4274. if (core.isDevMode() && this.isNgZoneEnabled && !core.NgZone.isInAngularZone()) {
  4275. this.console.warn("Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?");
  4276. }
  4277. var urlTree = isUrlTree(url) ? url : this.parseUrl(url);
  4278. var mergedTree = this.urlHandlingStrategy.merge(urlTree, this.rawUrlTree);
  4279. return this.scheduleNavigation(mergedTree, 'imperative', null, extras);
  4280. };
  4281. /**
  4282. * Navigate based on the provided array of commands and a starting point.
  4283. * If no starting route is provided, the navigation is absolute.
  4284. *
  4285. * Returns a promise that:
  4286. * - resolves to 'true' when navigation succeeds,
  4287. * - resolves to 'false' when navigation fails,
  4288. * - is rejected when an error happens.
  4289. *
  4290. * @usageNotes
  4291. *
  4292. * ### Example
  4293. *
  4294. * ```
  4295. * router.navigate(['team', 33, 'user', 11], {relativeTo: route});
  4296. *
  4297. * // Navigate without updating the URL
  4298. * router.navigate(['team', 33, 'user', 11], {relativeTo: route, skipLocationChange: true});
  4299. * ```
  4300. *
  4301. * The first parameter of `navigate()` is a delta to be applied to the current URL
  4302. * or the one provided in the `relativeTo` property of the second parameter (the
  4303. * `NavigationExtras`).
  4304. *
  4305. * In order to affect this browser's `history.state` entry, the `state`
  4306. * parameter can be passed. This must be an object because the router
  4307. * will add the `navigationId` property to this object before creating
  4308. * the new history item.
  4309. */
  4310. Router.prototype.navigate = function (commands, extras) {
  4311. if (extras === void 0) { extras = { skipLocationChange: false }; }
  4312. validateCommands(commands);
  4313. return this.navigateByUrl(this.createUrlTree(commands, extras), extras);
  4314. };
  4315. /** Serializes a `UrlTree` into a string */
  4316. Router.prototype.serializeUrl = function (url) { return this.urlSerializer.serialize(url); };
  4317. /** Parses a string into a `UrlTree` */
  4318. Router.prototype.parseUrl = function (url) {
  4319. var urlTree;
  4320. try {
  4321. urlTree = this.urlSerializer.parse(url);
  4322. }
  4323. catch (e) {
  4324. urlTree = this.malformedUriErrorHandler(e, this.urlSerializer, url);
  4325. }
  4326. return urlTree;
  4327. };
  4328. /** Returns whether the url is activated */
  4329. Router.prototype.isActive = function (url, exact) {
  4330. if (isUrlTree(url)) {
  4331. return containsTree(this.currentUrlTree, url, exact);
  4332. }
  4333. var urlTree = this.parseUrl(url);
  4334. return containsTree(this.currentUrlTree, urlTree, exact);
  4335. };
  4336. Router.prototype.removeEmptyProps = function (params) {
  4337. return Object.keys(params).reduce(function (result, key) {
  4338. var value = params[key];
  4339. if (value !== null && value !== undefined) {
  4340. result[key] = value;
  4341. }
  4342. return result;
  4343. }, {});
  4344. };
  4345. Router.prototype.processNavigations = function () {
  4346. var _this = this;
  4347. this.navigations.subscribe(function (t) {
  4348. _this.navigated = true;
  4349. _this.lastSuccessfulId = t.id;
  4350. _this.events
  4351. .next(new NavigationEnd(t.id, _this.serializeUrl(t.extractedUrl), _this.serializeUrl(_this.currentUrlTree)));
  4352. _this.lastSuccessfulNavigation = _this.currentNavigation;
  4353. _this.currentNavigation = null;
  4354. t.resolve(true);
  4355. }, function (e) { _this.console.warn("Unhandled Navigation Error: "); });
  4356. };
  4357. Router.prototype.scheduleNavigation = function (rawUrl, source, restoredState, extras) {
  4358. var lastNavigation = this.getTransition();
  4359. // If the user triggers a navigation imperatively (e.g., by using navigateByUrl),
  4360. // and that navigation results in 'replaceState' that leads to the same URL,
  4361. // we should skip those.
  4362. if (lastNavigation && source !== 'imperative' && lastNavigation.source === 'imperative' &&
  4363. lastNavigation.rawUrl.toString() === rawUrl.toString()) {
  4364. return Promise.resolve(true); // return value is not used
  4365. }
  4366. // Because of a bug in IE and Edge, the location class fires two events (popstate and
  4367. // hashchange) every single time. The second one should be ignored. Otherwise, the URL will
  4368. // flicker. Handles the case when a popstate was emitted first.
  4369. if (lastNavigation && source == 'hashchange' && lastNavigation.source === 'popstate' &&
  4370. lastNavigation.rawUrl.toString() === rawUrl.toString()) {
  4371. return Promise.resolve(true); // return value is not used
  4372. }
  4373. // Because of a bug in IE and Edge, the location class fires two events (popstate and
  4374. // hashchange) every single time. The second one should be ignored. Otherwise, the URL will
  4375. // flicker. Handles the case when a hashchange was emitted first.
  4376. if (lastNavigation && source == 'popstate' && lastNavigation.source === 'hashchange' &&
  4377. lastNavigation.rawUrl.toString() === rawUrl.toString()) {
  4378. return Promise.resolve(true); // return value is not used
  4379. }
  4380. var resolve = null;
  4381. var reject = null;
  4382. var promise = new Promise(function (res, rej) {
  4383. resolve = res;
  4384. reject = rej;
  4385. });
  4386. var id = ++this.navigationId;
  4387. this.setTransition({
  4388. id: id,
  4389. source: source,
  4390. restoredState: restoredState,
  4391. currentUrlTree: this.currentUrlTree,
  4392. currentRawUrl: this.rawUrlTree, rawUrl: rawUrl, extras: extras, resolve: resolve, reject: reject, promise: promise,
  4393. currentSnapshot: this.routerState.snapshot,
  4394. currentRouterState: this.routerState
  4395. });
  4396. // Make sure that the error is propagated even though `processNavigations` catch
  4397. // handler does not rethrow
  4398. return promise.catch(function (e) { return Promise.reject(e); });
  4399. };
  4400. Router.prototype.setBrowserUrl = function (url, replaceUrl, id, state) {
  4401. var path = this.urlSerializer.serialize(url);
  4402. state = state || {};
  4403. if (this.location.isCurrentPathEqualTo(path) || replaceUrl) {
  4404. // TODO(jasonaden): Remove first `navigationId` and rely on `ng` namespace.
  4405. this.location.replaceState(path, '', __assign({}, state, { navigationId: id }));
  4406. }
  4407. else {
  4408. this.location.go(path, '', __assign({}, state, { navigationId: id }));
  4409. }
  4410. };
  4411. Router.prototype.resetStateAndUrl = function (storedState, storedUrl, rawUrl) {
  4412. this.routerState = storedState;
  4413. this.currentUrlTree = storedUrl;
  4414. this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
  4415. this.resetUrlToCurrentUrlTree();
  4416. };
  4417. Router.prototype.resetUrlToCurrentUrlTree = function () {
  4418. this.location.replaceState(this.urlSerializer.serialize(this.rawUrlTree), '', { navigationId: this.lastSuccessfulId });
  4419. };
  4420. return Router;
  4421. }());
  4422. function validateCommands(commands) {
  4423. for (var i = 0; i < commands.length; i++) {
  4424. var cmd = commands[i];
  4425. if (cmd == null) {
  4426. throw new Error("The requested path contains " + cmd + " segment at index " + i);
  4427. }
  4428. }
  4429. }
  4430. /**
  4431. * @license
  4432. * Copyright Google Inc. All Rights Reserved.
  4433. *
  4434. * Use of this source code is governed by an MIT-style license that can be
  4435. * found in the LICENSE file at https://angular.io/license
  4436. */
  4437. /**
  4438. * @description
  4439. *
  4440. * Lets you link to specific routes in your app.
  4441. *
  4442. * Consider the following route configuration:
  4443. * `[{ path: 'user/:name', component: UserCmp }]`.
  4444. * When linking to this `user/:name` route, you use the `RouterLink` directive.
  4445. *
  4446. * If the link is static, you can use the directive as follows:
  4447. * `<a routerLink="/user/bob">link to user component</a>`
  4448. *
  4449. * If you use dynamic values to generate the link, you can pass an array of path
  4450. * segments, followed by the params for each segment.
  4451. *
  4452. * For instance `['/team', teamId, 'user', userName, {details: true}]`
  4453. * means that we want to generate a link to `/team/11/user/bob;details=true`.
  4454. *
  4455. * Multiple static segments can be merged into one
  4456. * (e.g., `['/team/11/user', userName, {details: true}]`).
  4457. *
  4458. * The first segment name can be prepended with `/`, `./`, or `../`:
  4459. * * If the first segment begins with `/`, the router will look up the route from the root of the
  4460. * app.
  4461. * * If the first segment begins with `./`, or doesn't begin with a slash, the router will
  4462. * instead look in the children of the current activated route.
  4463. * * And if the first segment begins with `../`, the router will go up one level.
  4464. *
  4465. * You can set query params and fragment as follows:
  4466. *
  4467. * ```
  4468. * <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
  4469. * link to user component
  4470. * </a>
  4471. * ```
  4472. * RouterLink will use these to generate this link: `/user/bob#education?debug=true`.
  4473. *
  4474. * (Deprecated in v4.0.0 use `queryParamsHandling` instead) You can also tell the
  4475. * directive to preserve the current query params and fragment:
  4476. *
  4477. * ```
  4478. * <a [routerLink]="['/user/bob']" preserveQueryParams preserveFragment>
  4479. * link to user component
  4480. * </a>
  4481. * ```
  4482. *
  4483. * You can tell the directive how to handle queryParams. Available options are:
  4484. * - `'merge'`: merge the queryParams into the current queryParams
  4485. * - `'preserve'`: preserve the current queryParams
  4486. * - default/`''`: use the queryParams only
  4487. *
  4488. * Same options for {@link NavigationExtras#queryParamsHandling
  4489. * NavigationExtras#queryParamsHandling}.
  4490. *
  4491. * ```
  4492. * <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" queryParamsHandling="merge">
  4493. * link to user component
  4494. * </a>
  4495. * ```
  4496. *
  4497. * You can provide a `state` value to be persisted to the browser's History.state
  4498. * property (See https://developer.mozilla.org/en-US/docs/Web/API/History#Properties). It's
  4499. * used as follows:
  4500. *
  4501. * ```
  4502. * <a [routerLink]="['/user/bob']" [state]="{tracingId: 123}">
  4503. * link to user component
  4504. * </a>
  4505. * ```
  4506. *
  4507. * And later the value can be read from the router through `router.getCurrentNavigation`.
  4508. * For example, to capture the `tracingId` above during the `NavigationStart` event:
  4509. *
  4510. * ```
  4511. * // Get NavigationStart events
  4512. * router.events.pipe(filter(e => e instanceof NavigationStart)).subscribe(e => {
  4513. * const navigation = router.getCurrentNavigation();
  4514. * tracingService.trace({id: navigation.extras.state.tracingId});
  4515. * });
  4516. * ```
  4517. *
  4518. * The router link directive always treats the provided input as a delta to the current url.
  4519. *
  4520. * For instance, if the current url is `/user/(box//aux:team)`.
  4521. *
  4522. * Then the following link `<a [routerLink]="['/user/jim']">Jim</a>` will generate the link
  4523. * `/user/(jim//aux:team)`.
  4524. *
  4525. * See {@link Router#createUrlTree createUrlTree} for more information.
  4526. *
  4527. * @ngModule RouterModule
  4528. *
  4529. * @publicApi
  4530. */
  4531. var RouterLink = /** @class */ (function () {
  4532. function RouterLink(router, route, tabIndex, renderer, el) {
  4533. this.router = router;
  4534. this.route = route;
  4535. this.commands = [];
  4536. if (tabIndex == null) {
  4537. renderer.setAttribute(el.nativeElement, 'tabindex', '0');
  4538. }
  4539. }
  4540. Object.defineProperty(RouterLink.prototype, "routerLink", {
  4541. set: function (commands) {
  4542. if (commands != null) {
  4543. this.commands = Array.isArray(commands) ? commands : [commands];
  4544. }
  4545. else {
  4546. this.commands = [];
  4547. }
  4548. },
  4549. enumerable: true,
  4550. configurable: true
  4551. });
  4552. Object.defineProperty(RouterLink.prototype, "preserveQueryParams", {
  4553. /**
  4554. * @deprecated 4.0.0 use `queryParamsHandling` instead.
  4555. */
  4556. set: function (value) {
  4557. if (core.isDevMode() && console && console.warn) {
  4558. console.warn('preserveQueryParams is deprecated!, use queryParamsHandling instead.');
  4559. }
  4560. this.preserve = value;
  4561. },
  4562. enumerable: true,
  4563. configurable: true
  4564. });
  4565. RouterLink.prototype.onClick = function () {
  4566. var extras = {
  4567. skipLocationChange: attrBoolValue(this.skipLocationChange),
  4568. replaceUrl: attrBoolValue(this.replaceUrl),
  4569. };
  4570. this.router.navigateByUrl(this.urlTree, extras);
  4571. return true;
  4572. };
  4573. Object.defineProperty(RouterLink.prototype, "urlTree", {
  4574. get: function () {
  4575. return this.router.createUrlTree(this.commands, {
  4576. relativeTo: this.route,
  4577. queryParams: this.queryParams,
  4578. fragment: this.fragment,
  4579. preserveQueryParams: attrBoolValue(this.preserve),
  4580. queryParamsHandling: this.queryParamsHandling,
  4581. preserveFragment: attrBoolValue(this.preserveFragment),
  4582. });
  4583. },
  4584. enumerable: true,
  4585. configurable: true
  4586. });
  4587. __decorate([
  4588. core.Input(),
  4589. __metadata("design:type", Object)
  4590. ], RouterLink.prototype, "queryParams", void 0);
  4591. __decorate([
  4592. core.Input(),
  4593. __metadata("design:type", String)
  4594. ], RouterLink.prototype, "fragment", void 0);
  4595. __decorate([
  4596. core.Input(),
  4597. __metadata("design:type", String)
  4598. ], RouterLink.prototype, "queryParamsHandling", void 0);
  4599. __decorate([
  4600. core.Input(),
  4601. __metadata("design:type", Boolean)
  4602. ], RouterLink.prototype, "preserveFragment", void 0);
  4603. __decorate([
  4604. core.Input(),
  4605. __metadata("design:type", Boolean)
  4606. ], RouterLink.prototype, "skipLocationChange", void 0);
  4607. __decorate([
  4608. core.Input(),
  4609. __metadata("design:type", Boolean)
  4610. ], RouterLink.prototype, "replaceUrl", void 0);
  4611. __decorate([
  4612. core.Input(),
  4613. __metadata("design:type", Object)
  4614. ], RouterLink.prototype, "state", void 0);
  4615. __decorate([
  4616. core.Input(),
  4617. __metadata("design:type", Object),
  4618. __metadata("design:paramtypes", [Object])
  4619. ], RouterLink.prototype, "routerLink", null);
  4620. __decorate([
  4621. core.Input(),
  4622. __metadata("design:type", Boolean),
  4623. __metadata("design:paramtypes", [Boolean])
  4624. ], RouterLink.prototype, "preserveQueryParams", null);
  4625. __decorate([
  4626. core.HostListener('click'),
  4627. __metadata("design:type", Function),
  4628. __metadata("design:paramtypes", []),
  4629. __metadata("design:returntype", Boolean)
  4630. ], RouterLink.prototype, "onClick", null);
  4631. RouterLink = __decorate([
  4632. core.Directive({ selector: ':not(a):not(area)[routerLink]' }),
  4633. __param(2, core.Attribute('tabindex')),
  4634. __metadata("design:paramtypes", [Router, ActivatedRoute, String, core.Renderer2, core.ElementRef])
  4635. ], RouterLink);
  4636. return RouterLink;
  4637. }());
  4638. /**
  4639. * @description
  4640. *
  4641. * Lets you link to specific routes in your app.
  4642. *
  4643. * See `RouterLink` for more information.
  4644. *
  4645. * @ngModule RouterModule
  4646. *
  4647. * @publicApi
  4648. */
  4649. var RouterLinkWithHref = /** @class */ (function () {
  4650. function RouterLinkWithHref(router, route, locationStrategy) {
  4651. var _this = this;
  4652. this.router = router;
  4653. this.route = route;
  4654. this.locationStrategy = locationStrategy;
  4655. this.commands = [];
  4656. this.subscription = router.events.subscribe(function (s) {
  4657. if (s instanceof NavigationEnd) {
  4658. _this.updateTargetUrlAndHref();
  4659. }
  4660. });
  4661. }
  4662. Object.defineProperty(RouterLinkWithHref.prototype, "routerLink", {
  4663. set: function (commands) {
  4664. if (commands != null) {
  4665. this.commands = Array.isArray(commands) ? commands : [commands];
  4666. }
  4667. else {
  4668. this.commands = [];
  4669. }
  4670. },
  4671. enumerable: true,
  4672. configurable: true
  4673. });
  4674. Object.defineProperty(RouterLinkWithHref.prototype, "preserveQueryParams", {
  4675. set: function (value) {
  4676. if (core.isDevMode() && console && console.warn) {
  4677. console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
  4678. }
  4679. this.preserve = value;
  4680. },
  4681. enumerable: true,
  4682. configurable: true
  4683. });
  4684. RouterLinkWithHref.prototype.ngOnChanges = function (changes) { this.updateTargetUrlAndHref(); };
  4685. RouterLinkWithHref.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); };
  4686. RouterLinkWithHref.prototype.onClick = function (button, ctrlKey, metaKey, shiftKey) {
  4687. if (button !== 0 || ctrlKey || metaKey || shiftKey) {
  4688. return true;
  4689. }
  4690. if (typeof this.target === 'string' && this.target != '_self') {
  4691. return true;
  4692. }
  4693. var extras = {
  4694. skipLocationChange: attrBoolValue(this.skipLocationChange),
  4695. replaceUrl: attrBoolValue(this.replaceUrl),
  4696. state: this.state
  4697. };
  4698. this.router.navigateByUrl(this.urlTree, extras);
  4699. return false;
  4700. };
  4701. RouterLinkWithHref.prototype.updateTargetUrlAndHref = function () {
  4702. this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
  4703. };
  4704. Object.defineProperty(RouterLinkWithHref.prototype, "urlTree", {
  4705. get: function () {
  4706. return this.router.createUrlTree(this.commands, {
  4707. relativeTo: this.route,
  4708. queryParams: this.queryParams,
  4709. fragment: this.fragment,
  4710. preserveQueryParams: attrBoolValue(this.preserve),
  4711. queryParamsHandling: this.queryParamsHandling,
  4712. preserveFragment: attrBoolValue(this.preserveFragment),
  4713. });
  4714. },
  4715. enumerable: true,
  4716. configurable: true
  4717. });
  4718. __decorate([
  4719. core.HostBinding('attr.target'), core.Input(),
  4720. __metadata("design:type", String)
  4721. ], RouterLinkWithHref.prototype, "target", void 0);
  4722. __decorate([
  4723. core.Input(),
  4724. __metadata("design:type", Object)
  4725. ], RouterLinkWithHref.prototype, "queryParams", void 0);
  4726. __decorate([
  4727. core.Input(),
  4728. __metadata("design:type", String)
  4729. ], RouterLinkWithHref.prototype, "fragment", void 0);
  4730. __decorate([
  4731. core.Input(),
  4732. __metadata("design:type", String)
  4733. ], RouterLinkWithHref.prototype, "queryParamsHandling", void 0);
  4734. __decorate([
  4735. core.Input(),
  4736. __metadata("design:type", Boolean)
  4737. ], RouterLinkWithHref.prototype, "preserveFragment", void 0);
  4738. __decorate([
  4739. core.Input(),
  4740. __metadata("design:type", Boolean)
  4741. ], RouterLinkWithHref.prototype, "skipLocationChange", void 0);
  4742. __decorate([
  4743. core.Input(),
  4744. __metadata("design:type", Boolean)
  4745. ], RouterLinkWithHref.prototype, "replaceUrl", void 0);
  4746. __decorate([
  4747. core.Input(),
  4748. __metadata("design:type", Object)
  4749. ], RouterLinkWithHref.prototype, "state", void 0);
  4750. __decorate([
  4751. core.HostBinding(),
  4752. __metadata("design:type", String)
  4753. ], RouterLinkWithHref.prototype, "href", void 0);
  4754. __decorate([
  4755. core.Input(),
  4756. __metadata("design:type", Object),
  4757. __metadata("design:paramtypes", [Object])
  4758. ], RouterLinkWithHref.prototype, "routerLink", null);
  4759. __decorate([
  4760. core.Input(),
  4761. __metadata("design:type", Boolean),
  4762. __metadata("design:paramtypes", [Boolean])
  4763. ], RouterLinkWithHref.prototype, "preserveQueryParams", null);
  4764. __decorate([
  4765. core.HostListener('click', ['$event.button', '$event.ctrlKey', '$event.metaKey', '$event.shiftKey']),
  4766. __metadata("design:type", Function),
  4767. __metadata("design:paramtypes", [Number, Boolean, Boolean, Boolean]),
  4768. __metadata("design:returntype", Boolean)
  4769. ], RouterLinkWithHref.prototype, "onClick", null);
  4770. RouterLinkWithHref = __decorate([
  4771. core.Directive({ selector: 'a[routerLink],area[routerLink]' }),
  4772. __metadata("design:paramtypes", [Router, ActivatedRoute,
  4773. common.LocationStrategy])
  4774. ], RouterLinkWithHref);
  4775. return RouterLinkWithHref;
  4776. }());
  4777. function attrBoolValue(s) {
  4778. return s === '' || !!s;
  4779. }
  4780. /**
  4781. * @license
  4782. * Copyright Google Inc. All Rights Reserved.
  4783. *
  4784. * Use of this source code is governed by an MIT-style license that can be
  4785. * found in the LICENSE file at https://angular.io/license
  4786. */
  4787. /**
  4788. *
  4789. * @description
  4790. *
  4791. * Lets you add a CSS class to an element when the link's route becomes active.
  4792. *
  4793. * This directive lets you add a CSS class to an element when the link's route
  4794. * becomes active.
  4795. *
  4796. * Consider the following example:
  4797. *
  4798. * ```
  4799. * <a routerLink="/user/bob" routerLinkActive="active-link">Bob</a>
  4800. * ```
  4801. *
  4802. * When the url is either '/user' or '/user/bob', the active-link class will
  4803. * be added to the `a` tag. If the url changes, the class will be removed.
  4804. *
  4805. * You can set more than one class, as follows:
  4806. *
  4807. * ```
  4808. * <a routerLink="/user/bob" routerLinkActive="class1 class2">Bob</a>
  4809. * <a routerLink="/user/bob" [routerLinkActive]="['class1', 'class2']">Bob</a>
  4810. * ```
  4811. *
  4812. * You can configure RouterLinkActive by passing `exact: true`. This will add the classes
  4813. * only when the url matches the link exactly.
  4814. *
  4815. * ```
  4816. * <a routerLink="/user/bob" routerLinkActive="active-link" [routerLinkActiveOptions]="{exact:
  4817. * true}">Bob</a>
  4818. * ```
  4819. *
  4820. * You can assign the RouterLinkActive instance to a template variable and directly check
  4821. * the `isActive` status.
  4822. * ```
  4823. * <a routerLink="/user/bob" routerLinkActive #rla="routerLinkActive">
  4824. * Bob {{ rla.isActive ? '(already open)' : ''}}
  4825. * </a>
  4826. * ```
  4827. *
  4828. * Finally, you can apply the RouterLinkActive directive to an ancestor of a RouterLink.
  4829. *
  4830. * ```
  4831. * <div routerLinkActive="active-link" [routerLinkActiveOptions]="{exact: true}">
  4832. * <a routerLink="/user/jim">Jim</a>
  4833. * <a routerLink="/user/bob">Bob</a>
  4834. * </div>
  4835. * ```
  4836. *
  4837. * This will set the active-link class on the div tag if the url is either '/user/jim' or
  4838. * '/user/bob'.
  4839. *
  4840. * @ngModule RouterModule
  4841. *
  4842. * @publicApi
  4843. */
  4844. var RouterLinkActive = /** @class */ (function () {
  4845. function RouterLinkActive(router, element, renderer, link, linkWithHref) {
  4846. var _this = this;
  4847. this.router = router;
  4848. this.element = element;
  4849. this.renderer = renderer;
  4850. this.link = link;
  4851. this.linkWithHref = linkWithHref;
  4852. this.classes = [];
  4853. this.isActive = false;
  4854. this.routerLinkActiveOptions = { exact: false };
  4855. this.subscription = router.events.subscribe(function (s) {
  4856. if (s instanceof NavigationEnd) {
  4857. _this.update();
  4858. }
  4859. });
  4860. }
  4861. RouterLinkActive.prototype.ngAfterContentInit = function () {
  4862. var _this = this;
  4863. this.links.changes.subscribe(function (_) { return _this.update(); });
  4864. this.linksWithHrefs.changes.subscribe(function (_) { return _this.update(); });
  4865. this.update();
  4866. };
  4867. Object.defineProperty(RouterLinkActive.prototype, "routerLinkActive", {
  4868. set: function (data) {
  4869. var classes = Array.isArray(data) ? data : data.split(' ');
  4870. this.classes = classes.filter(function (c) { return !!c; });
  4871. },
  4872. enumerable: true,
  4873. configurable: true
  4874. });
  4875. RouterLinkActive.prototype.ngOnChanges = function (changes) { this.update(); };
  4876. RouterLinkActive.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); };
  4877. RouterLinkActive.prototype.update = function () {
  4878. var _this = this;
  4879. if (!this.links || !this.linksWithHrefs || !this.router.navigated)
  4880. return;
  4881. Promise.resolve().then(function () {
  4882. var hasActiveLinks = _this.hasActiveLinks();
  4883. if (_this.isActive !== hasActiveLinks) {
  4884. _this.isActive = hasActiveLinks;
  4885. _this.classes.forEach(function (c) {
  4886. if (hasActiveLinks) {
  4887. _this.renderer.addClass(_this.element.nativeElement, c);
  4888. }
  4889. else {
  4890. _this.renderer.removeClass(_this.element.nativeElement, c);
  4891. }
  4892. });
  4893. }
  4894. });
  4895. };
  4896. RouterLinkActive.prototype.isLinkActive = function (router) {
  4897. var _this = this;
  4898. return function (link) {
  4899. return router.isActive(link.urlTree, _this.routerLinkActiveOptions.exact);
  4900. };
  4901. };
  4902. RouterLinkActive.prototype.hasActiveLinks = function () {
  4903. var isActiveCheckFn = this.isLinkActive(this.router);
  4904. return this.link && isActiveCheckFn(this.link) ||
  4905. this.linkWithHref && isActiveCheckFn(this.linkWithHref) ||
  4906. this.links.some(isActiveCheckFn) || this.linksWithHrefs.some(isActiveCheckFn);
  4907. };
  4908. __decorate([
  4909. core.ContentChildren(RouterLink, { descendants: true }),
  4910. __metadata("design:type", core.QueryList)
  4911. ], RouterLinkActive.prototype, "links", void 0);
  4912. __decorate([
  4913. core.ContentChildren(RouterLinkWithHref, { descendants: true }),
  4914. __metadata("design:type", core.QueryList)
  4915. ], RouterLinkActive.prototype, "linksWithHrefs", void 0);
  4916. __decorate([
  4917. core.Input(),
  4918. __metadata("design:type", Object)
  4919. ], RouterLinkActive.prototype, "routerLinkActiveOptions", void 0);
  4920. __decorate([
  4921. core.Input(),
  4922. __metadata("design:type", Object),
  4923. __metadata("design:paramtypes", [Object])
  4924. ], RouterLinkActive.prototype, "routerLinkActive", null);
  4925. RouterLinkActive = __decorate([
  4926. core.Directive({
  4927. selector: '[routerLinkActive]',
  4928. exportAs: 'routerLinkActive',
  4929. }),
  4930. __param(3, core.Optional()),
  4931. __param(4, core.Optional()),
  4932. __metadata("design:paramtypes", [Router, core.ElementRef, core.Renderer2,
  4933. RouterLink,
  4934. RouterLinkWithHref])
  4935. ], RouterLinkActive);
  4936. return RouterLinkActive;
  4937. }());
  4938. /**
  4939. * @license
  4940. * Copyright Google Inc. All Rights Reserved.
  4941. *
  4942. * Use of this source code is governed by an MIT-style license that can be
  4943. * found in the LICENSE file at https://angular.io/license
  4944. */
  4945. /**
  4946. * Store contextual information about a `RouterOutlet`
  4947. *
  4948. * @publicApi
  4949. */
  4950. var OutletContext = /** @class */ (function () {
  4951. function OutletContext() {
  4952. this.outlet = null;
  4953. this.route = null;
  4954. this.resolver = null;
  4955. this.children = new ChildrenOutletContexts();
  4956. this.attachRef = null;
  4957. }
  4958. return OutletContext;
  4959. }());
  4960. /**
  4961. * Store contextual information about the children (= nested) `RouterOutlet`
  4962. *
  4963. * @publicApi
  4964. */
  4965. var ChildrenOutletContexts = /** @class */ (function () {
  4966. function ChildrenOutletContexts() {
  4967. // contexts for child outlets, by name.
  4968. this.contexts = new Map();
  4969. }
  4970. /** Called when a `RouterOutlet` directive is instantiated */
  4971. ChildrenOutletContexts.prototype.onChildOutletCreated = function (childName, outlet) {
  4972. var context = this.getOrCreateContext(childName);
  4973. context.outlet = outlet;
  4974. this.contexts.set(childName, context);
  4975. };
  4976. /**
  4977. * Called when a `RouterOutlet` directive is destroyed.
  4978. * We need to keep the context as the outlet could be destroyed inside a NgIf and might be
  4979. * re-created later.
  4980. */
  4981. ChildrenOutletContexts.prototype.onChildOutletDestroyed = function (childName) {
  4982. var context = this.getContext(childName);
  4983. if (context) {
  4984. context.outlet = null;
  4985. }
  4986. };
  4987. /**
  4988. * Called when the corresponding route is deactivated during navigation.
  4989. * Because the component get destroyed, all children outlet are destroyed.
  4990. */
  4991. ChildrenOutletContexts.prototype.onOutletDeactivated = function () {
  4992. var contexts = this.contexts;
  4993. this.contexts = new Map();
  4994. return contexts;
  4995. };
  4996. ChildrenOutletContexts.prototype.onOutletReAttached = function (contexts) { this.contexts = contexts; };
  4997. ChildrenOutletContexts.prototype.getOrCreateContext = function (childName) {
  4998. var context = this.getContext(childName);
  4999. if (!context) {
  5000. context = new OutletContext();
  5001. this.contexts.set(childName, context);
  5002. }
  5003. return context;
  5004. };
  5005. ChildrenOutletContexts.prototype.getContext = function (childName) { return this.contexts.get(childName) || null; };
  5006. return ChildrenOutletContexts;
  5007. }());
  5008. /**
  5009. * @license
  5010. * Copyright Google Inc. All Rights Reserved.
  5011. *
  5012. * Use of this source code is governed by an MIT-style license that can be
  5013. * found in the LICENSE file at https://angular.io/license
  5014. */
  5015. /**
  5016. * @description
  5017. *
  5018. * Acts as a placeholder that Angular dynamically fills based on the current router state.
  5019. *
  5020. * ```
  5021. * <router-outlet></router-outlet>
  5022. * <router-outlet name='left'></router-outlet>
  5023. * <router-outlet name='right'></router-outlet>
  5024. * ```
  5025. *
  5026. * A router outlet will emit an activate event any time a new component is being instantiated,
  5027. * and a deactivate event when it is being destroyed.
  5028. *
  5029. * ```
  5030. * <router-outlet
  5031. * (activate)='onActivate($event)'
  5032. * (deactivate)='onDeactivate($event)'></router-outlet>
  5033. * ```
  5034. * @ngModule RouterModule
  5035. *
  5036. * @publicApi
  5037. */
  5038. var RouterOutlet = /** @class */ (function () {
  5039. function RouterOutlet(parentContexts, location, resolver, name, changeDetector) {
  5040. this.parentContexts = parentContexts;
  5041. this.location = location;
  5042. this.resolver = resolver;
  5043. this.changeDetector = changeDetector;
  5044. this.activated = null;
  5045. this._activatedRoute = null;
  5046. this.activateEvents = new core.EventEmitter();
  5047. this.deactivateEvents = new core.EventEmitter();
  5048. this.name = name || PRIMARY_OUTLET;
  5049. parentContexts.onChildOutletCreated(this.name, this);
  5050. }
  5051. RouterOutlet.prototype.ngOnDestroy = function () { this.parentContexts.onChildOutletDestroyed(this.name); };
  5052. RouterOutlet.prototype.ngOnInit = function () {
  5053. if (!this.activated) {
  5054. // If the outlet was not instantiated at the time the route got activated we need to populate
  5055. // the outlet when it is initialized (ie inside a NgIf)
  5056. var context = this.parentContexts.getContext(this.name);
  5057. if (context && context.route) {
  5058. if (context.attachRef) {
  5059. // `attachRef` is populated when there is an existing component to mount
  5060. this.attach(context.attachRef, context.route);
  5061. }
  5062. else {
  5063. // otherwise the component defined in the configuration is created
  5064. this.activateWith(context.route, context.resolver || null);
  5065. }
  5066. }
  5067. }
  5068. };
  5069. Object.defineProperty(RouterOutlet.prototype, "isActivated", {
  5070. get: function () { return !!this.activated; },
  5071. enumerable: true,
  5072. configurable: true
  5073. });
  5074. Object.defineProperty(RouterOutlet.prototype, "component", {
  5075. get: function () {
  5076. if (!this.activated)
  5077. throw new Error('Outlet is not activated');
  5078. return this.activated.instance;
  5079. },
  5080. enumerable: true,
  5081. configurable: true
  5082. });
  5083. Object.defineProperty(RouterOutlet.prototype, "activatedRoute", {
  5084. get: function () {
  5085. if (!this.activated)
  5086. throw new Error('Outlet is not activated');
  5087. return this._activatedRoute;
  5088. },
  5089. enumerable: true,
  5090. configurable: true
  5091. });
  5092. Object.defineProperty(RouterOutlet.prototype, "activatedRouteData", {
  5093. get: function () {
  5094. if (this._activatedRoute) {
  5095. return this._activatedRoute.snapshot.data;
  5096. }
  5097. return {};
  5098. },
  5099. enumerable: true,
  5100. configurable: true
  5101. });
  5102. /**
  5103. * Called when the `RouteReuseStrategy` instructs to detach the subtree
  5104. */
  5105. RouterOutlet.prototype.detach = function () {
  5106. if (!this.activated)
  5107. throw new Error('Outlet is not activated');
  5108. this.location.detach();
  5109. var cmp = this.activated;
  5110. this.activated = null;
  5111. this._activatedRoute = null;
  5112. return cmp;
  5113. };
  5114. /**
  5115. * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree
  5116. */
  5117. RouterOutlet.prototype.attach = function (ref, activatedRoute) {
  5118. this.activated = ref;
  5119. this._activatedRoute = activatedRoute;
  5120. this.location.insert(ref.hostView);
  5121. };
  5122. RouterOutlet.prototype.deactivate = function () {
  5123. if (this.activated) {
  5124. var c = this.component;
  5125. this.activated.destroy();
  5126. this.activated = null;
  5127. this._activatedRoute = null;
  5128. this.deactivateEvents.emit(c);
  5129. }
  5130. };
  5131. RouterOutlet.prototype.activateWith = function (activatedRoute, resolver) {
  5132. if (this.isActivated) {
  5133. throw new Error('Cannot activate an already activated outlet');
  5134. }
  5135. this._activatedRoute = activatedRoute;
  5136. var snapshot = activatedRoute._futureSnapshot;
  5137. var component = snapshot.routeConfig.component;
  5138. resolver = resolver || this.resolver;
  5139. var factory = resolver.resolveComponentFactory(component);
  5140. var childContexts = this.parentContexts.getOrCreateContext(this.name).children;
  5141. var injector = new OutletInjector(activatedRoute, childContexts, this.location.injector);
  5142. this.activated = this.location.createComponent(factory, this.location.length, injector);
  5143. // Calling `markForCheck` to make sure we will run the change detection when the
  5144. // `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
  5145. this.changeDetector.markForCheck();
  5146. this.activateEvents.emit(this.activated.instance);
  5147. };
  5148. __decorate([
  5149. core.Output('activate'),
  5150. __metadata("design:type", Object)
  5151. ], RouterOutlet.prototype, "activateEvents", void 0);
  5152. __decorate([
  5153. core.Output('deactivate'),
  5154. __metadata("design:type", Object)
  5155. ], RouterOutlet.prototype, "deactivateEvents", void 0);
  5156. RouterOutlet = __decorate([
  5157. core.Directive({ selector: 'router-outlet', exportAs: 'outlet' }),
  5158. __param(3, core.Attribute('name')),
  5159. __metadata("design:paramtypes", [ChildrenOutletContexts, core.ViewContainerRef,
  5160. core.ComponentFactoryResolver, String, core.ChangeDetectorRef])
  5161. ], RouterOutlet);
  5162. return RouterOutlet;
  5163. }());
  5164. var OutletInjector = /** @class */ (function () {
  5165. function OutletInjector(route, childContexts, parent) {
  5166. this.route = route;
  5167. this.childContexts = childContexts;
  5168. this.parent = parent;
  5169. }
  5170. OutletInjector.prototype.get = function (token, notFoundValue) {
  5171. if (token === ActivatedRoute) {
  5172. return this.route;
  5173. }
  5174. if (token === ChildrenOutletContexts) {
  5175. return this.childContexts;
  5176. }
  5177. return this.parent.get(token, notFoundValue);
  5178. };
  5179. return OutletInjector;
  5180. }());
  5181. /**
  5182. *@license
  5183. *Copyright Google Inc. All Rights Reserved.
  5184. *
  5185. *Use of this source code is governed by an MIT-style license that can be
  5186. *found in the LICENSE file at https://angular.io/license
  5187. */
  5188. /**
  5189. * @description
  5190. *
  5191. * Provides a preloading strategy.
  5192. *
  5193. * @publicApi
  5194. */
  5195. var PreloadingStrategy = /** @class */ (function () {
  5196. function PreloadingStrategy() {
  5197. }
  5198. return PreloadingStrategy;
  5199. }());
  5200. /**
  5201. * @description
  5202. *
  5203. * Provides a preloading strategy that preloads all modules as quickly as possible.
  5204. *
  5205. * ```
  5206. * RouteModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules})
  5207. * ```
  5208. *
  5209. * @publicApi
  5210. */
  5211. var PreloadAllModules = /** @class */ (function () {
  5212. function PreloadAllModules() {
  5213. }
  5214. PreloadAllModules.prototype.preload = function (route, fn) {
  5215. return fn().pipe(operators.catchError(function () { return rxjs.of(null); }));
  5216. };
  5217. return PreloadAllModules;
  5218. }());
  5219. /**
  5220. * @description
  5221. *
  5222. * Provides a preloading strategy that does not preload any modules.
  5223. *
  5224. * This strategy is enabled by default.
  5225. *
  5226. * @publicApi
  5227. */
  5228. var NoPreloading = /** @class */ (function () {
  5229. function NoPreloading() {
  5230. }
  5231. NoPreloading.prototype.preload = function (route, fn) { return rxjs.of(null); };
  5232. return NoPreloading;
  5233. }());
  5234. /**
  5235. * The preloader optimistically loads all router configurations to
  5236. * make navigations into lazily-loaded sections of the application faster.
  5237. *
  5238. * The preloader runs in the background. When the router bootstraps, the preloader
  5239. * starts listening to all navigation events. After every such event, the preloader
  5240. * will check if any configurations can be loaded lazily.
  5241. *
  5242. * If a route is protected by `canLoad` guards, the preloaded will not load it.
  5243. *
  5244. * @publicApi
  5245. */
  5246. var RouterPreloader = /** @class */ (function () {
  5247. function RouterPreloader(router, moduleLoader, compiler, injector, preloadingStrategy) {
  5248. this.router = router;
  5249. this.injector = injector;
  5250. this.preloadingStrategy = preloadingStrategy;
  5251. var onStartLoad = function (r) { return router.triggerEvent(new RouteConfigLoadStart(r)); };
  5252. var onEndLoad = function (r) { return router.triggerEvent(new RouteConfigLoadEnd(r)); };
  5253. this.loader = new RouterConfigLoader(moduleLoader, compiler, onStartLoad, onEndLoad);
  5254. }
  5255. RouterPreloader.prototype.setUpPreloading = function () {
  5256. var _this = this;
  5257. this.subscription =
  5258. this.router.events
  5259. .pipe(operators.filter(function (e) { return e instanceof NavigationEnd; }), operators.concatMap(function () { return _this.preload(); }))
  5260. .subscribe(function () { });
  5261. };
  5262. RouterPreloader.prototype.preload = function () {
  5263. var ngModule = this.injector.get(core.NgModuleRef);
  5264. return this.processRoutes(ngModule, this.router.config);
  5265. };
  5266. // TODO(jasonaden): This class relies on code external to the class to call setUpPreloading. If
  5267. // this hasn't been done, ngOnDestroy will fail as this.subscription will be undefined. This
  5268. // should be refactored.
  5269. RouterPreloader.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); };
  5270. RouterPreloader.prototype.processRoutes = function (ngModule, routes) {
  5271. var e_1, _a;
  5272. var res = [];
  5273. try {
  5274. for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
  5275. var route = routes_1_1.value;
  5276. // we already have the config loaded, just recurse
  5277. if (route.loadChildren && !route.canLoad && route._loadedConfig) {
  5278. var childConfig = route._loadedConfig;
  5279. res.push(this.processRoutes(childConfig.module, childConfig.routes));
  5280. // no config loaded, fetch the config
  5281. }
  5282. else if (route.loadChildren && !route.canLoad) {
  5283. res.push(this.preloadConfig(ngModule, route));
  5284. // recurse into children
  5285. }
  5286. else if (route.children) {
  5287. res.push(this.processRoutes(ngModule, route.children));
  5288. }
  5289. }
  5290. }
  5291. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  5292. finally {
  5293. try {
  5294. if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
  5295. }
  5296. finally { if (e_1) throw e_1.error; }
  5297. }
  5298. return rxjs.from(res).pipe(operators.mergeAll(), operators.map(function (_) { return void 0; }));
  5299. };
  5300. RouterPreloader.prototype.preloadConfig = function (ngModule, route) {
  5301. var _this = this;
  5302. return this.preloadingStrategy.preload(route, function () {
  5303. var loaded$ = _this.loader.load(ngModule.injector, route);
  5304. return loaded$.pipe(operators.mergeMap(function (config) {
  5305. route._loadedConfig = config;
  5306. return _this.processRoutes(config.module, config.routes);
  5307. }));
  5308. });
  5309. };
  5310. RouterPreloader = __decorate([
  5311. core.Injectable(),
  5312. __metadata("design:paramtypes", [Router, core.NgModuleFactoryLoader, core.Compiler,
  5313. core.Injector, PreloadingStrategy])
  5314. ], RouterPreloader);
  5315. return RouterPreloader;
  5316. }());
  5317. /**
  5318. * @license
  5319. * Copyright Google Inc. All Rights Reserved.
  5320. *
  5321. * Use of this source code is governed by an MIT-style license that can be
  5322. * found in the LICENSE file at https://angular.io/license
  5323. */
  5324. var RouterScroller = /** @class */ (function () {
  5325. function RouterScroller(router,
  5326. /** @docsNotRequired */ viewportScroller, options) {
  5327. if (options === void 0) { options = {}; }
  5328. this.router = router;
  5329. this.viewportScroller = viewportScroller;
  5330. this.options = options;
  5331. this.lastId = 0;
  5332. this.lastSource = 'imperative';
  5333. this.restoredId = 0;
  5334. this.store = {};
  5335. // Default both options to 'disabled'
  5336. options.scrollPositionRestoration = options.scrollPositionRestoration || 'disabled';
  5337. options.anchorScrolling = options.anchorScrolling || 'disabled';
  5338. }
  5339. RouterScroller.prototype.init = function () {
  5340. // we want to disable the automatic scrolling because having two places
  5341. // responsible for scrolling results race conditions, especially given
  5342. // that browser don't implement this behavior consistently
  5343. if (this.options.scrollPositionRestoration !== 'disabled') {
  5344. this.viewportScroller.setHistoryScrollRestoration('manual');
  5345. }
  5346. this.routerEventsSubscription = this.createScrollEvents();
  5347. this.scrollEventsSubscription = this.consumeScrollEvents();
  5348. };
  5349. RouterScroller.prototype.createScrollEvents = function () {
  5350. var _this = this;
  5351. return this.router.events.subscribe(function (e) {
  5352. if (e instanceof NavigationStart) {
  5353. // store the scroll position of the current stable navigations.
  5354. _this.store[_this.lastId] = _this.viewportScroller.getScrollPosition();
  5355. _this.lastSource = e.navigationTrigger;
  5356. _this.restoredId = e.restoredState ? e.restoredState.navigationId : 0;
  5357. }
  5358. else if (e instanceof NavigationEnd) {
  5359. _this.lastId = e.id;
  5360. _this.scheduleScrollEvent(e, _this.router.parseUrl(e.urlAfterRedirects).fragment);
  5361. }
  5362. });
  5363. };
  5364. RouterScroller.prototype.consumeScrollEvents = function () {
  5365. var _this = this;
  5366. return this.router.events.subscribe(function (e) {
  5367. if (!(e instanceof Scroll))
  5368. return;
  5369. // a popstate event. The pop state event will always ignore anchor scrolling.
  5370. if (e.position) {
  5371. if (_this.options.scrollPositionRestoration === 'top') {
  5372. _this.viewportScroller.scrollToPosition([0, 0]);
  5373. }
  5374. else if (_this.options.scrollPositionRestoration === 'enabled') {
  5375. _this.viewportScroller.scrollToPosition(e.position);
  5376. }
  5377. // imperative navigation "forward"
  5378. }
  5379. else {
  5380. if (e.anchor && _this.options.anchorScrolling === 'enabled') {
  5381. _this.viewportScroller.scrollToAnchor(e.anchor);
  5382. }
  5383. else if (_this.options.scrollPositionRestoration !== 'disabled') {
  5384. _this.viewportScroller.scrollToPosition([0, 0]);
  5385. }
  5386. }
  5387. });
  5388. };
  5389. RouterScroller.prototype.scheduleScrollEvent = function (routerEvent, anchor) {
  5390. this.router.triggerEvent(new Scroll(routerEvent, this.lastSource === 'popstate' ? this.store[this.restoredId] : null, anchor));
  5391. };
  5392. RouterScroller.prototype.ngOnDestroy = function () {
  5393. if (this.routerEventsSubscription) {
  5394. this.routerEventsSubscription.unsubscribe();
  5395. }
  5396. if (this.scrollEventsSubscription) {
  5397. this.scrollEventsSubscription.unsubscribe();
  5398. }
  5399. };
  5400. return RouterScroller;
  5401. }());
  5402. /**
  5403. * @license
  5404. * Copyright Google Inc. All Rights Reserved.
  5405. *
  5406. * Use of this source code is governed by an MIT-style license that can be
  5407. * found in the LICENSE file at https://angular.io/license
  5408. */
  5409. /**
  5410. * @description
  5411. *
  5412. * Contains a list of directives
  5413. *
  5414. *
  5415. */
  5416. var ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref, RouterLinkActive, ɵEmptyOutletComponent];
  5417. /**
  5418. * @description
  5419. *
  5420. * Is used in DI to configure the router.
  5421. *
  5422. * @publicApi
  5423. */
  5424. var ROUTER_CONFIGURATION = new core.InjectionToken('ROUTER_CONFIGURATION');
  5425. /**
  5426. * @docsNotRequired
  5427. */
  5428. var ROUTER_FORROOT_GUARD = new core.InjectionToken('ROUTER_FORROOT_GUARD');
  5429. var ɵ0 = { enableTracing: false };
  5430. var ROUTER_PROVIDERS = [
  5431. common.Location,
  5432. { provide: UrlSerializer, useClass: DefaultUrlSerializer },
  5433. {
  5434. provide: Router,
  5435. useFactory: setupRouter,
  5436. deps: [
  5437. core.ApplicationRef, UrlSerializer, ChildrenOutletContexts, common.Location, core.Injector,
  5438. core.NgModuleFactoryLoader, core.Compiler, ROUTES, ROUTER_CONFIGURATION,
  5439. [UrlHandlingStrategy, new core.Optional()], [RouteReuseStrategy, new core.Optional()]
  5440. ]
  5441. },
  5442. ChildrenOutletContexts,
  5443. { provide: ActivatedRoute, useFactory: rootRoute, deps: [Router] },
  5444. { provide: core.NgModuleFactoryLoader, useClass: core.SystemJsNgModuleLoader },
  5445. RouterPreloader,
  5446. NoPreloading,
  5447. PreloadAllModules,
  5448. { provide: ROUTER_CONFIGURATION, useValue: ɵ0 },
  5449. ];
  5450. function routerNgProbeToken() {
  5451. return new core.NgProbeToken('Router', Router);
  5452. }
  5453. /**
  5454. * @usageNotes
  5455. *
  5456. * RouterModule can be imported multiple times: once per lazily-loaded bundle.
  5457. * Since the router deals with a global shared resource--location, we cannot have
  5458. * more than one router service active.
  5459. *
  5460. * That is why there are two ways to create the module: `RouterModule.forRoot` and
  5461. * `RouterModule.forChild`.
  5462. *
  5463. * * `forRoot` creates a module that contains all the directives, the given routes, and the router
  5464. * service itself.
  5465. * * `forChild` creates a module that contains all the directives and the given routes, but does not
  5466. * include the router service.
  5467. *
  5468. * When registered at the root, the module should be used as follows
  5469. *
  5470. * ```
  5471. * @NgModule({
  5472. * imports: [RouterModule.forRoot(ROUTES)]
  5473. * })
  5474. * class MyNgModule {}
  5475. * ```
  5476. *
  5477. * For submodules and lazy loaded submodules the module should be used as follows:
  5478. *
  5479. * ```
  5480. * @NgModule({
  5481. * imports: [RouterModule.forChild(ROUTES)]
  5482. * })
  5483. * class MyNgModule {}
  5484. * ```
  5485. *
  5486. * @description
  5487. *
  5488. * Adds router directives and providers.
  5489. *
  5490. * Managing state transitions is one of the hardest parts of building applications. This is
  5491. * especially true on the web, where you also need to ensure that the state is reflected in the URL.
  5492. * In addition, we often want to split applications into multiple bundles and load them on demand.
  5493. * Doing this transparently is not trivial.
  5494. *
  5495. * The Angular router solves these problems. Using the router, you can declaratively specify
  5496. * application states, manage state transitions while taking care of the URL, and load bundles on
  5497. * demand.
  5498. *
  5499. * [Read this developer guide](https://angular.io/docs/ts/latest/guide/router.html) to get an
  5500. * overview of how the router should be used.
  5501. *
  5502. * @publicApi
  5503. */
  5504. var RouterModule = /** @class */ (function () {
  5505. // Note: We are injecting the Router so it gets created eagerly...
  5506. function RouterModule(guard, router) {
  5507. }
  5508. RouterModule_1 = RouterModule;
  5509. /**
  5510. * Creates a module with all the router providers and directives. It also optionally sets up an
  5511. * application listener to perform an initial navigation.
  5512. *
  5513. * Configuration Options:
  5514. *
  5515. * * `enableTracing` Toggles whether the router should log all navigation events to the console.
  5516. * * `useHash` Enables the location strategy that uses the URL fragment instead of the history
  5517. * API.
  5518. * * `initialNavigation` Disables the initial navigation.
  5519. * * `errorHandler` Defines a custom error handler for failed navigations.
  5520. * * `preloadingStrategy` Configures a preloading strategy. See `PreloadAllModules`.
  5521. * * `onSameUrlNavigation` Define what the router should do if it receives a navigation request to
  5522. * the current URL.
  5523. * * `scrollPositionRestoration` Configures if the scroll position needs to be restored when
  5524. * navigating back.
  5525. * * `anchorScrolling` Configures if the router should scroll to the element when the url has a
  5526. * fragment.
  5527. * * `scrollOffset` Configures the scroll offset the router will use when scrolling to an element.
  5528. * * `paramsInheritanceStrategy` Defines how the router merges params, data and resolved data from
  5529. * parent to child routes.
  5530. * * `malformedUriErrorHandler` Defines a custom malformed uri error handler function. This
  5531. * handler is invoked when encodedURI contains invalid character sequences.
  5532. * * `urlUpdateStrategy` Defines when the router updates the browser URL. The default behavior is
  5533. * to update after successful navigation.
  5534. * * `relativeLinkResolution` Enables the correct relative link resolution in components with
  5535. * empty paths.
  5536. *
  5537. * See `ExtraOptions` for more details about the above options.
  5538. */
  5539. RouterModule.forRoot = function (routes, config) {
  5540. return {
  5541. ngModule: RouterModule_1,
  5542. providers: [
  5543. ROUTER_PROVIDERS,
  5544. provideRoutes(routes),
  5545. {
  5546. provide: ROUTER_FORROOT_GUARD,
  5547. useFactory: provideForRootGuard,
  5548. deps: [[Router, new core.Optional(), new core.SkipSelf()]]
  5549. },
  5550. { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },
  5551. {
  5552. provide: common.LocationStrategy,
  5553. useFactory: provideLocationStrategy,
  5554. deps: [
  5555. common.PlatformLocation, [new core.Inject(common.APP_BASE_HREF), new core.Optional()], ROUTER_CONFIGURATION
  5556. ]
  5557. },
  5558. {
  5559. provide: RouterScroller,
  5560. useFactory: createRouterScroller,
  5561. deps: [Router, common.ViewportScroller, ROUTER_CONFIGURATION]
  5562. },
  5563. {
  5564. provide: PreloadingStrategy,
  5565. useExisting: config && config.preloadingStrategy ? config.preloadingStrategy :
  5566. NoPreloading
  5567. },
  5568. { provide: core.NgProbeToken, multi: true, useFactory: routerNgProbeToken },
  5569. provideRouterInitializer(),
  5570. ],
  5571. };
  5572. };
  5573. /**
  5574. * Creates a module with all the router directives and a provider registering routes.
  5575. */
  5576. RouterModule.forChild = function (routes) {
  5577. return { ngModule: RouterModule_1, providers: [provideRoutes(routes)] };
  5578. };
  5579. var RouterModule_1;
  5580. RouterModule = RouterModule_1 = __decorate([
  5581. core.NgModule({
  5582. declarations: ROUTER_DIRECTIVES,
  5583. exports: ROUTER_DIRECTIVES,
  5584. entryComponents: [ɵEmptyOutletComponent]
  5585. }),
  5586. __param(0, core.Optional()), __param(0, core.Inject(ROUTER_FORROOT_GUARD)), __param(1, core.Optional()),
  5587. __metadata("design:paramtypes", [Object, Router])
  5588. ], RouterModule);
  5589. return RouterModule;
  5590. }());
  5591. function createRouterScroller(router, viewportScroller, config) {
  5592. if (config.scrollOffset) {
  5593. viewportScroller.setOffset(config.scrollOffset);
  5594. }
  5595. return new RouterScroller(router, viewportScroller, config);
  5596. }
  5597. function provideLocationStrategy(platformLocationStrategy, baseHref, options) {
  5598. if (options === void 0) { options = {}; }
  5599. return options.useHash ? new common.HashLocationStrategy(platformLocationStrategy, baseHref) :
  5600. new common.PathLocationStrategy(platformLocationStrategy, baseHref);
  5601. }
  5602. function provideForRootGuard(router) {
  5603. if (router) {
  5604. throw new Error("RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead.");
  5605. }
  5606. return 'guarded';
  5607. }
  5608. /**
  5609. * @description
  5610. *
  5611. * Registers routes.
  5612. *
  5613. * @usageNotes
  5614. * ### Example
  5615. *
  5616. * ```
  5617. * @NgModule({
  5618. * imports: [RouterModule.forChild(ROUTES)],
  5619. * providers: [provideRoutes(EXTRA_ROUTES)]
  5620. * })
  5621. * class MyNgModule {}
  5622. * ```
  5623. *
  5624. * @publicApi
  5625. */
  5626. function provideRoutes(routes) {
  5627. return [
  5628. { provide: core.ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes },
  5629. { provide: ROUTES, multi: true, useValue: routes },
  5630. ];
  5631. }
  5632. function setupRouter(ref, urlSerializer, contexts, location, injector, loader, compiler, config, opts, urlHandlingStrategy, routeReuseStrategy) {
  5633. if (opts === void 0) { opts = {}; }
  5634. var router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, flatten(config));
  5635. if (urlHandlingStrategy) {
  5636. router.urlHandlingStrategy = urlHandlingStrategy;
  5637. }
  5638. if (routeReuseStrategy) {
  5639. router.routeReuseStrategy = routeReuseStrategy;
  5640. }
  5641. if (opts.errorHandler) {
  5642. router.errorHandler = opts.errorHandler;
  5643. }
  5644. if (opts.malformedUriErrorHandler) {
  5645. router.malformedUriErrorHandler = opts.malformedUriErrorHandler;
  5646. }
  5647. if (opts.enableTracing) {
  5648. var dom_1 = platformBrowser.ɵgetDOM();
  5649. router.events.subscribe(function (e) {
  5650. dom_1.logGroup("Router Event: " + e.constructor.name);
  5651. dom_1.log(e.toString());
  5652. dom_1.log(e);
  5653. dom_1.logGroupEnd();
  5654. });
  5655. }
  5656. if (opts.onSameUrlNavigation) {
  5657. router.onSameUrlNavigation = opts.onSameUrlNavigation;
  5658. }
  5659. if (opts.paramsInheritanceStrategy) {
  5660. router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
  5661. }
  5662. if (opts.urlUpdateStrategy) {
  5663. router.urlUpdateStrategy = opts.urlUpdateStrategy;
  5664. }
  5665. if (opts.relativeLinkResolution) {
  5666. router.relativeLinkResolution = opts.relativeLinkResolution;
  5667. }
  5668. return router;
  5669. }
  5670. function rootRoute(router) {
  5671. return router.routerState.root;
  5672. }
  5673. /**
  5674. * To initialize the router properly we need to do in two steps:
  5675. *
  5676. * We need to start the navigation in a APP_INITIALIZER to block the bootstrap if
  5677. * a resolver or a guards executes asynchronously. Second, we need to actually run
  5678. * activation in a BOOTSTRAP_LISTENER. We utilize the afterPreactivation
  5679. * hook provided by the router to do that.
  5680. *
  5681. * The router navigation starts, reaches the point when preactivation is done, and then
  5682. * pauses. It waits for the hook to be resolved. We then resolve it only in a bootstrap listener.
  5683. */
  5684. var RouterInitializer = /** @class */ (function () {
  5685. function RouterInitializer(injector) {
  5686. this.injector = injector;
  5687. this.initNavigation = false;
  5688. this.resultOfPreactivationDone = new rxjs.Subject();
  5689. }
  5690. RouterInitializer.prototype.appInitializer = function () {
  5691. var _this = this;
  5692. var p = this.injector.get(common.LOCATION_INITIALIZED, Promise.resolve(null));
  5693. return p.then(function () {
  5694. var resolve = null;
  5695. var res = new Promise(function (r) { return resolve = r; });
  5696. var router = _this.injector.get(Router);
  5697. var opts = _this.injector.get(ROUTER_CONFIGURATION);
  5698. if (_this.isLegacyDisabled(opts) || _this.isLegacyEnabled(opts)) {
  5699. resolve(true);
  5700. }
  5701. else if (opts.initialNavigation === 'disabled') {
  5702. router.setUpLocationChangeListener();
  5703. resolve(true);
  5704. }
  5705. else if (opts.initialNavigation === 'enabled') {
  5706. router.hooks.afterPreactivation = function () {
  5707. // only the initial navigation should be delayed
  5708. if (!_this.initNavigation) {
  5709. _this.initNavigation = true;
  5710. resolve(true);
  5711. return _this.resultOfPreactivationDone;
  5712. // subsequent navigations should not be delayed
  5713. }
  5714. else {
  5715. return rxjs.of(null);
  5716. }
  5717. };
  5718. router.initialNavigation();
  5719. }
  5720. else {
  5721. throw new Error("Invalid initialNavigation options: '" + opts.initialNavigation + "'");
  5722. }
  5723. return res;
  5724. });
  5725. };
  5726. RouterInitializer.prototype.bootstrapListener = function (bootstrappedComponentRef) {
  5727. var opts = this.injector.get(ROUTER_CONFIGURATION);
  5728. var preloader = this.injector.get(RouterPreloader);
  5729. var routerScroller = this.injector.get(RouterScroller);
  5730. var router = this.injector.get(Router);
  5731. var ref = this.injector.get(core.ApplicationRef);
  5732. if (bootstrappedComponentRef !== ref.components[0]) {
  5733. return;
  5734. }
  5735. if (this.isLegacyEnabled(opts)) {
  5736. router.initialNavigation();
  5737. }
  5738. else if (this.isLegacyDisabled(opts)) {
  5739. router.setUpLocationChangeListener();
  5740. }
  5741. preloader.setUpPreloading();
  5742. routerScroller.init();
  5743. router.resetRootComponentType(ref.componentTypes[0]);
  5744. this.resultOfPreactivationDone.next(null);
  5745. this.resultOfPreactivationDone.complete();
  5746. };
  5747. RouterInitializer.prototype.isLegacyEnabled = function (opts) {
  5748. return opts.initialNavigation === 'legacy_enabled' || opts.initialNavigation === true ||
  5749. opts.initialNavigation === undefined;
  5750. };
  5751. RouterInitializer.prototype.isLegacyDisabled = function (opts) {
  5752. return opts.initialNavigation === 'legacy_disabled' || opts.initialNavigation === false;
  5753. };
  5754. RouterInitializer = __decorate([
  5755. core.Injectable(),
  5756. __metadata("design:paramtypes", [core.Injector])
  5757. ], RouterInitializer);
  5758. return RouterInitializer;
  5759. }());
  5760. function getAppInitializer(r) {
  5761. return r.appInitializer.bind(r);
  5762. }
  5763. function getBootstrapListener(r) {
  5764. return r.bootstrapListener.bind(r);
  5765. }
  5766. /**
  5767. * A token for the router initializer that will be called after the app is bootstrapped.
  5768. *
  5769. * @publicApi
  5770. */
  5771. var ROUTER_INITIALIZER = new core.InjectionToken('Router Initializer');
  5772. function provideRouterInitializer() {
  5773. return [
  5774. RouterInitializer,
  5775. {
  5776. provide: core.APP_INITIALIZER,
  5777. multi: true,
  5778. useFactory: getAppInitializer,
  5779. deps: [RouterInitializer]
  5780. },
  5781. { provide: ROUTER_INITIALIZER, useFactory: getBootstrapListener, deps: [RouterInitializer] },
  5782. { provide: core.APP_BOOTSTRAP_LISTENER, multi: true, useExisting: ROUTER_INITIALIZER },
  5783. ];
  5784. }
  5785. /**
  5786. * @license
  5787. * Copyright Google Inc. All Rights Reserved.
  5788. *
  5789. * Use of this source code is governed by an MIT-style license that can be
  5790. * found in the LICENSE file at https://angular.io/license
  5791. */
  5792. /**
  5793. * @publicApi
  5794. */
  5795. var VERSION = new core.Version('8.1.0');
  5796. /**
  5797. * @license
  5798. * Copyright Google Inc. All Rights Reserved.
  5799. *
  5800. * Use of this source code is governed by an MIT-style license that can be
  5801. * found in the LICENSE file at https://angular.io/license
  5802. */
  5803. /**
  5804. * @license
  5805. * Copyright Google Inc. All Rights Reserved.
  5806. *
  5807. * Use of this source code is governed by an MIT-style license that can be
  5808. * found in the LICENSE file at https://angular.io/license
  5809. */
  5810. /**
  5811. * @license
  5812. * Copyright Google Inc. All Rights Reserved.
  5813. *
  5814. * Use of this source code is governed by an MIT-style license that can be
  5815. * found in the LICENSE file at https://angular.io/license
  5816. */
  5817. // This file only reexports content of the `src` folder. Keep it that way.
  5818. /**
  5819. * @license
  5820. * Copyright Google Inc. All Rights Reserved.
  5821. *
  5822. * Use of this source code is governed by an MIT-style license that can be
  5823. * found in the LICENSE file at https://angular.io/license
  5824. */
  5825. /**
  5826. * Generated bundle index. Do not edit.
  5827. */
  5828. exports.ɵangular_packages_router_router_l = ɵEmptyOutletComponent;
  5829. exports.ɵEmptyOutletComponent = ɵEmptyOutletComponent;
  5830. exports.ɵangular_packages_router_router_a = ROUTER_FORROOT_GUARD;
  5831. exports.ɵangular_packages_router_router_h = RouterInitializer;
  5832. exports.ɵangular_packages_router_router_c = createRouterScroller;
  5833. exports.ɵangular_packages_router_router_i = getAppInitializer;
  5834. exports.ɵangular_packages_router_router_j = getBootstrapListener;
  5835. exports.ɵangular_packages_router_router_e = provideForRootGuard;
  5836. exports.ɵangular_packages_router_router_d = provideLocationStrategy;
  5837. exports.ɵangular_packages_router_router_k = provideRouterInitializer;
  5838. exports.ɵangular_packages_router_router_g = rootRoute;
  5839. exports.ɵangular_packages_router_router_b = routerNgProbeToken;
  5840. exports.ɵangular_packages_router_router_f = setupRouter;
  5841. exports.ɵangular_packages_router_router_o = RouterScroller;
  5842. exports.ɵangular_packages_router_router_m = Tree;
  5843. exports.ɵangular_packages_router_router_n = TreeNode;
  5844. exports.RouterLink = RouterLink;
  5845. exports.RouterLinkWithHref = RouterLinkWithHref;
  5846. exports.RouterLinkActive = RouterLinkActive;
  5847. exports.RouterOutlet = RouterOutlet;
  5848. exports.ActivationEnd = ActivationEnd;
  5849. exports.ActivationStart = ActivationStart;
  5850. exports.ChildActivationEnd = ChildActivationEnd;
  5851. exports.ChildActivationStart = ChildActivationStart;
  5852. exports.GuardsCheckEnd = GuardsCheckEnd;
  5853. exports.GuardsCheckStart = GuardsCheckStart;
  5854. exports.NavigationCancel = NavigationCancel;
  5855. exports.NavigationEnd = NavigationEnd;
  5856. exports.NavigationError = NavigationError;
  5857. exports.NavigationStart = NavigationStart;
  5858. exports.ResolveEnd = ResolveEnd;
  5859. exports.ResolveStart = ResolveStart;
  5860. exports.RouteConfigLoadEnd = RouteConfigLoadEnd;
  5861. exports.RouteConfigLoadStart = RouteConfigLoadStart;
  5862. exports.RouterEvent = RouterEvent;
  5863. exports.RoutesRecognized = RoutesRecognized;
  5864. exports.Scroll = Scroll;
  5865. exports.RouteReuseStrategy = RouteReuseStrategy;
  5866. exports.Router = Router;
  5867. exports.ROUTES = ROUTES;
  5868. exports.ROUTER_CONFIGURATION = ROUTER_CONFIGURATION;
  5869. exports.ROUTER_INITIALIZER = ROUTER_INITIALIZER;
  5870. exports.RouterModule = RouterModule;
  5871. exports.provideRoutes = provideRoutes;
  5872. exports.ChildrenOutletContexts = ChildrenOutletContexts;
  5873. exports.OutletContext = OutletContext;
  5874. exports.NoPreloading = NoPreloading;
  5875. exports.PreloadAllModules = PreloadAllModules;
  5876. exports.PreloadingStrategy = PreloadingStrategy;
  5877. exports.RouterPreloader = RouterPreloader;
  5878. exports.ActivatedRoute = ActivatedRoute;
  5879. exports.ActivatedRouteSnapshot = ActivatedRouteSnapshot;
  5880. exports.RouterState = RouterState;
  5881. exports.RouterStateSnapshot = RouterStateSnapshot;
  5882. exports.PRIMARY_OUTLET = PRIMARY_OUTLET;
  5883. exports.convertToParamMap = convertToParamMap;
  5884. exports.UrlHandlingStrategy = UrlHandlingStrategy;
  5885. exports.DefaultUrlSerializer = DefaultUrlSerializer;
  5886. exports.UrlSegment = UrlSegment;
  5887. exports.UrlSegmentGroup = UrlSegmentGroup;
  5888. exports.UrlSerializer = UrlSerializer;
  5889. exports.UrlTree = UrlTree;
  5890. exports.VERSION = VERSION;
  5891. exports.ɵROUTER_PROVIDERS = ROUTER_PROVIDERS;
  5892. exports.ɵflatten = flatten;
  5893. Object.defineProperty(exports, '__esModule', { value: true });
  5894. }));
  5895. //# sourceMappingURL=router.umd.js.map