router.umd.js 244 KB

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