index.d.ts 168 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807
  1. /**
  2. * @license Angular v19.2.4
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import * as i0 from '@angular/core';
  7. import { Type, ProviderToken, NgModuleFactory, Provider, EnvironmentProviders, EnvironmentInjector, OnDestroy, OnInit, ComponentRef, EventEmitter, SimpleChanges, InjectionToken, Signal, OnChanges, Renderer2, ElementRef, AfterContentInit, QueryList, ChangeDetectorRef, Injector, Compiler, ModuleWithProviders, Version } from '@angular/core';
  8. import { Observable } from 'rxjs';
  9. import { LocationStrategy } from '@angular/common';
  10. import * as _angular_router from '@angular/router';
  11. import { Title } from '@angular/platform-browser';
  12. /**
  13. * The primary routing outlet.
  14. *
  15. * @publicApi
  16. */
  17. declare const PRIMARY_OUTLET = "primary";
  18. /**
  19. * A collection of matrix and query URL parameters.
  20. * @see {@link convertToParamMap}
  21. * @see {@link ParamMap}
  22. *
  23. * @publicApi
  24. */
  25. type Params = {
  26. [key: string]: any;
  27. };
  28. /**
  29. * A map that provides access to the required and optional parameters
  30. * specific to a route.
  31. * The map supports retrieving a single value with `get()`
  32. * or multiple values with `getAll()`.
  33. *
  34. * @see [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
  35. *
  36. * @publicApi
  37. */
  38. interface ParamMap {
  39. /**
  40. * Reports whether the map contains a given parameter.
  41. * @param name The parameter name.
  42. * @returns True if the map contains the given parameter, false otherwise.
  43. */
  44. has(name: string): boolean;
  45. /**
  46. * Retrieves a single value for a parameter.
  47. * @param name The parameter name.
  48. * @return The parameter's single value,
  49. * or the first value if the parameter has multiple values,
  50. * or `null` when there is no such parameter.
  51. */
  52. get(name: string): string | null;
  53. /**
  54. * Retrieves multiple values for a parameter.
  55. * @param name The parameter name.
  56. * @return An array containing one or more values,
  57. * or an empty array if there is no such parameter.
  58. *
  59. */
  60. getAll(name: string): string[];
  61. /** Names of the parameters in the map. */
  62. readonly keys: string[];
  63. }
  64. /**
  65. * Converts a `Params` instance to a `ParamMap`.
  66. * @param params The instance to convert.
  67. * @returns The new map instance.
  68. *
  69. * @publicApi
  70. */
  71. declare function convertToParamMap(params: Params): ParamMap;
  72. /**
  73. * Matches the route configuration (`route`) against the actual URL (`segments`).
  74. *
  75. * When no matcher is defined on a `Route`, this is the matcher used by the Router by default.
  76. *
  77. * @param segments The remaining unmatched segments in the current navigation
  78. * @param segmentGroup The current segment group being matched
  79. * @param route The `Route` to match against.
  80. *
  81. * @see {@link UrlMatchResult}
  82. * @see {@link Route}
  83. *
  84. * @returns The resulting match information or `null` if the `route` should not match.
  85. * @publicApi
  86. */
  87. declare function defaultUrlMatcher(segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult | null;
  88. /**
  89. * A set of options which specify how to determine if a `UrlTree` is active, given the `UrlTree`
  90. * for the current router state.
  91. *
  92. * @publicApi
  93. * @see {@link Router#isActive}
  94. */
  95. interface IsActiveMatchOptions {
  96. /**
  97. * Defines the strategy for comparing the matrix parameters of two `UrlTree`s.
  98. *
  99. * The matrix parameter matching is dependent on the strategy for matching the
  100. * segments. That is, if the `paths` option is set to `'subset'`, only
  101. * the matrix parameters of the matching segments will be compared.
  102. *
  103. * - `'exact'`: Requires that matching segments also have exact matrix parameter
  104. * matches.
  105. * - `'subset'`: The matching segments in the router's active `UrlTree` may contain
  106. * extra matrix parameters, but those that exist in the `UrlTree` in question must match.
  107. * - `'ignored'`: When comparing `UrlTree`s, matrix params will be ignored.
  108. */
  109. matrixParams: 'exact' | 'subset' | 'ignored';
  110. /**
  111. * Defines the strategy for comparing the query parameters of two `UrlTree`s.
  112. *
  113. * - `'exact'`: the query parameters must match exactly.
  114. * - `'subset'`: the active `UrlTree` may contain extra parameters,
  115. * but must match the key and value of any that exist in the `UrlTree` in question.
  116. * - `'ignored'`: When comparing `UrlTree`s, query params will be ignored.
  117. */
  118. queryParams: 'exact' | 'subset' | 'ignored';
  119. /**
  120. * Defines the strategy for comparing the `UrlSegment`s of the `UrlTree`s.
  121. *
  122. * - `'exact'`: all segments in each `UrlTree` must match.
  123. * - `'subset'`: a `UrlTree` will be determined to be active if it
  124. * is a subtree of the active route. That is, the active route may contain extra
  125. * segments, but must at least have all the segments of the `UrlTree` in question.
  126. */
  127. paths: 'exact' | 'subset';
  128. /**
  129. * - `'exact'`: indicates that the `UrlTree` fragments must be equal.
  130. * - `'ignored'`: the fragments will not be compared when determining if a
  131. * `UrlTree` is active.
  132. */
  133. fragment: 'exact' | 'ignored';
  134. }
  135. /**
  136. * @description
  137. *
  138. * Represents the parsed URL.
  139. *
  140. * Since a router state is a tree, and the URL is nothing but a serialized state, the URL is a
  141. * serialized tree.
  142. * UrlTree is a data structure that provides a lot of affordances in dealing with URLs
  143. *
  144. * @usageNotes
  145. * ### Example
  146. *
  147. * ```ts
  148. * @Component({templateUrl:'template.html'})
  149. * class MyComponent {
  150. * constructor(router: Router) {
  151. * const tree: UrlTree =
  152. * router.parseUrl('/team/33/(user/victor//support:help)?debug=true#fragment');
  153. * const f = tree.fragment; // return 'fragment'
  154. * const q = tree.queryParams; // returns {debug: 'true'}
  155. * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
  156. * const s: UrlSegment[] = g.segments; // returns 2 segments 'team' and '33'
  157. * g.children[PRIMARY_OUTLET].segments; // returns 2 segments 'user' and 'victor'
  158. * g.children['support'].segments; // return 1 segment 'help'
  159. * }
  160. * }
  161. * ```
  162. *
  163. * @publicApi
  164. */
  165. declare class UrlTree {
  166. /** The root segment group of the URL tree */
  167. root: UrlSegmentGroup;
  168. /** The query params of the URL */
  169. queryParams: Params;
  170. /** The fragment of the URL */
  171. fragment: string | null;
  172. constructor(
  173. /** The root segment group of the URL tree */
  174. root?: UrlSegmentGroup,
  175. /** The query params of the URL */
  176. queryParams?: Params,
  177. /** The fragment of the URL */
  178. fragment?: string | null);
  179. get queryParamMap(): ParamMap;
  180. /** @docsNotRequired */
  181. toString(): string;
  182. }
  183. /**
  184. * @description
  185. *
  186. * Represents the parsed URL segment group.
  187. *
  188. * See `UrlTree` for more information.
  189. *
  190. * @publicApi
  191. */
  192. declare class UrlSegmentGroup {
  193. /** The URL segments of this group. See `UrlSegment` for more information */
  194. segments: UrlSegment[];
  195. /** The list of children of this group */
  196. children: {
  197. [key: string]: UrlSegmentGroup;
  198. };
  199. /** The parent node in the url tree */
  200. parent: UrlSegmentGroup | null;
  201. constructor(
  202. /** The URL segments of this group. See `UrlSegment` for more information */
  203. segments: UrlSegment[],
  204. /** The list of children of this group */
  205. children: {
  206. [key: string]: UrlSegmentGroup;
  207. });
  208. /** Whether the segment has child segments */
  209. hasChildren(): boolean;
  210. /** Number of child segments */
  211. get numberOfChildren(): number;
  212. /** @docsNotRequired */
  213. toString(): string;
  214. }
  215. /**
  216. * @description
  217. *
  218. * Represents a single URL segment.
  219. *
  220. * A UrlSegment is a part of a URL between the two slashes. It contains a path and the matrix
  221. * parameters associated with the segment.
  222. *
  223. * @usageNotes
  224. * ### Example
  225. *
  226. * ```ts
  227. * @Component({templateUrl:'template.html'})
  228. * class MyComponent {
  229. * constructor(router: Router) {
  230. * const tree: UrlTree = router.parseUrl('/team;id=33');
  231. * const g: UrlSegmentGroup = tree.root.children[PRIMARY_OUTLET];
  232. * const s: UrlSegment[] = g.segments;
  233. * s[0].path; // returns 'team'
  234. * s[0].parameters; // returns {id: 33}
  235. * }
  236. * }
  237. * ```
  238. *
  239. * @publicApi
  240. */
  241. declare class UrlSegment {
  242. /** The path part of a URL segment */
  243. path: string;
  244. /** The matrix parameters associated with a segment */
  245. parameters: {
  246. [name: string]: string;
  247. };
  248. constructor(
  249. /** The path part of a URL segment */
  250. path: string,
  251. /** The matrix parameters associated with a segment */
  252. parameters: {
  253. [name: string]: string;
  254. });
  255. get parameterMap(): ParamMap;
  256. /** @docsNotRequired */
  257. toString(): string;
  258. }
  259. /**
  260. * @description
  261. *
  262. * Serializes and deserializes a URL string into a URL tree.
  263. *
  264. * The url serialization strategy is customizable. You can
  265. * make all URLs case insensitive by providing a custom UrlSerializer.
  266. *
  267. * See `DefaultUrlSerializer` for an example of a URL serializer.
  268. *
  269. * @publicApi
  270. */
  271. declare abstract class UrlSerializer {
  272. /** Parse a url into a `UrlTree` */
  273. abstract parse(url: string): UrlTree;
  274. /** Converts a `UrlTree` into a url */
  275. abstract serialize(tree: UrlTree): string;
  276. static ɵfac: i0.ɵɵFactoryDeclaration<UrlSerializer, never>;
  277. static ɵprov: i0.ɵɵInjectableDeclaration<UrlSerializer>;
  278. }
  279. /**
  280. * @description
  281. *
  282. * A default implementation of the `UrlSerializer`.
  283. *
  284. * Example URLs:
  285. *
  286. * ```
  287. * /inbox/33(popup:compose)
  288. * /inbox/33;open=true/messages/44
  289. * ```
  290. *
  291. * DefaultUrlSerializer uses parentheses to serialize secondary segments (e.g., popup:compose), the
  292. * colon syntax to specify the outlet, and the ';parameter=value' syntax (e.g., open=true) to
  293. * specify route specific parameters.
  294. *
  295. * @publicApi
  296. */
  297. declare class DefaultUrlSerializer implements UrlSerializer {
  298. /** Parses a url into a `UrlTree` */
  299. parse(url: string): UrlTree;
  300. /** Converts a `UrlTree` into a url */
  301. serialize(tree: UrlTree): string;
  302. }
  303. /**
  304. * How to handle a navigation request to the current URL. One of:
  305. *
  306. * - `'ignore'` : The router ignores the request if it is the same as the current state.
  307. * - `'reload'` : The router processes the URL even if it is not different from the current state.
  308. * One example of when you might want to use this option is if a `canMatch` guard depends on the
  309. * application state and initially rejects navigation to a route. After fixing the state, you want
  310. * to re-navigate to the same URL so that the route with the `canMatch` guard can activate.
  311. *
  312. * Note that this only configures whether or not the Route reprocesses the URL and triggers related
  313. * actions and events like redirects, guards, and resolvers. By default, the router re-uses a
  314. * component instance when it re-navigates to the same component type without visiting a different
  315. * component first. This behavior is configured by the `RouteReuseStrategy`. In order to reload
  316. * routed components on same url navigation, you need to set `onSameUrlNavigation` to `'reload'`
  317. * _and_ provide a `RouteReuseStrategy` which returns `false` for `shouldReuseRoute`. Additionally,
  318. * resolvers and most guards for routes do not run unless the path or path params have changed
  319. * (configured by `runGuardsAndResolvers`).
  320. *
  321. * @publicApi
  322. * @see {@link RouteReuseStrategy}
  323. * @see {@link RunGuardsAndResolvers}
  324. * @see {@link NavigationBehaviorOptions}
  325. * @see {@link RouterConfigOptions}
  326. */
  327. type OnSameUrlNavigation = 'reload' | 'ignore';
  328. /**
  329. * The `InjectionToken` and `@Injectable` classes for guards and resolvers are deprecated in favor
  330. * of plain JavaScript functions instead. Dependency injection can still be achieved using the
  331. * [`inject`](api/core/inject) function from `@angular/core` and an injectable class can be used as
  332. * a functional guard using [`inject`](api/core/inject): `canActivate: [() =>
  333. * inject(myGuard).canActivate()]`.
  334. *
  335. * @deprecated
  336. * @see {@link CanMatchFn}
  337. * @see {@link CanLoadFn}
  338. * @see {@link CanActivateFn}
  339. * @see {@link CanActivateChildFn}
  340. * @see {@link CanDeactivateFn}
  341. * @see {@link ResolveFn}
  342. * @see {@link /api/core/inject inject}
  343. * @publicApi
  344. */
  345. type DeprecatedGuard = ProviderToken<any> | any;
  346. /**
  347. * The supported types that can be returned from a `Router` guard.
  348. *
  349. * @see [Routing guide](guide/routing/common-router-tasks#preventing-unauthorized-access)
  350. * @publicApi
  351. */
  352. type GuardResult = boolean | UrlTree | RedirectCommand;
  353. /**
  354. * Can be returned by a `Router` guard to instruct the `Router` to redirect rather than continue
  355. * processing the path of the in-flight navigation. The `redirectTo` indicates _where_ the new
  356. * navigation should go to and the optional `navigationBehaviorOptions` can provide more information
  357. * about _how_ to perform the navigation.
  358. *
  359. * ```ts
  360. * const route: Route = {
  361. * path: "user/:userId",
  362. * component: User,
  363. * canActivate: [
  364. * () => {
  365. * const router = inject(Router);
  366. * const authService = inject(AuthenticationService);
  367. *
  368. * if (!authService.isLoggedIn()) {
  369. * const loginPath = router.parseUrl("/login");
  370. * return new RedirectCommand(loginPath, {
  371. * skipLocationChange: "true",
  372. * });
  373. * }
  374. *
  375. * return true;
  376. * },
  377. * ],
  378. * };
  379. * ```
  380. * @see [Routing guide](guide/routing/common-router-tasks#preventing-unauthorized-access)
  381. *
  382. * @publicApi
  383. */
  384. declare class RedirectCommand {
  385. readonly redirectTo: UrlTree;
  386. readonly navigationBehaviorOptions?: NavigationBehaviorOptions | undefined;
  387. constructor(redirectTo: UrlTree, navigationBehaviorOptions?: NavigationBehaviorOptions | undefined);
  388. }
  389. /**
  390. * Type used to represent a value which may be synchronous or async.
  391. *
  392. * @publicApi
  393. */
  394. type MaybeAsync<T> = T | Observable<T> | Promise<T>;
  395. /**
  396. * Represents a route configuration for the Router service.
  397. * An array of `Route` objects, used in `Router.config` and for nested route configurations
  398. * in `Route.children`.
  399. *
  400. * @see {@link Route}
  401. * @see {@link Router}
  402. * @see [Router configuration guide](guide/routing/router-reference#configuration)
  403. * @publicApi
  404. */
  405. type Routes = Route[];
  406. /**
  407. * Represents the result of matching URLs with a custom matching function.
  408. *
  409. * * `consumed` is an array of the consumed URL segments.
  410. * * `posParams` is a map of positional parameters.
  411. *
  412. * @see {@link UrlMatcher}
  413. * @publicApi
  414. */
  415. type UrlMatchResult = {
  416. consumed: UrlSegment[];
  417. posParams?: {
  418. [name: string]: UrlSegment;
  419. };
  420. };
  421. /**
  422. * A function for matching a route against URLs. Implement a custom URL matcher
  423. * for `Route.matcher` when a combination of `path` and `pathMatch`
  424. * is not expressive enough. Cannot be used together with `path` and `pathMatch`.
  425. *
  426. * The function takes the following arguments and returns a `UrlMatchResult` object.
  427. * * *segments* : An array of URL segments.
  428. * * *group* : A segment group.
  429. * * *route* : The route to match against.
  430. *
  431. * The following example implementation matches HTML files.
  432. *
  433. * ```ts
  434. * export function htmlFiles(url: UrlSegment[]) {
  435. * return url.length === 1 && url[0].path.endsWith('.html') ? ({consumed: url}) : null;
  436. * }
  437. *
  438. * export const routes = [{ matcher: htmlFiles, component: AnyComponent }];
  439. * ```
  440. *
  441. * @publicApi
  442. */
  443. type UrlMatcher = (segments: UrlSegment[], group: UrlSegmentGroup, route: Route) => UrlMatchResult | null;
  444. /**
  445. *
  446. * Represents static data associated with a particular route.
  447. *
  448. * @see {@link Route#data}
  449. *
  450. * @publicApi
  451. */
  452. type Data = {
  453. [key: string | symbol]: any;
  454. };
  455. /**
  456. *
  457. * Represents the resolved data associated with a particular route.
  458. *
  459. * Returning a `RedirectCommand` directs the router to cancel the current navigation and redirect to
  460. * the location provided in the `RedirectCommand`. Note that there are no ordering guarantees when
  461. * resolvers execute. If multiple resolvers would return a `RedirectCommand`, only the first one
  462. * returned will be used.
  463. *
  464. * @see {@link Route#resolve}
  465. *
  466. * @publicApi
  467. */
  468. type ResolveData = {
  469. [key: string | symbol]: ResolveFn<unknown> | DeprecatedGuard;
  470. };
  471. /**
  472. * An ES Module object with a default export of the given type.
  473. *
  474. * @see {@link Route#loadComponent}
  475. * @see {@link LoadChildrenCallback}
  476. *
  477. * @publicApi
  478. */
  479. interface DefaultExport<T> {
  480. /**
  481. * Default exports are bound under the name `"default"`, per the ES Module spec:
  482. * https://tc39.es/ecma262/#table-export-forms-mapping-to-exportentry-records
  483. */
  484. default: T;
  485. }
  486. /**
  487. *
  488. * A function that is called to resolve a collection of lazy-loaded routes.
  489. * Must be an arrow function of the following form:
  490. * `() => import('...').then(mod => mod.MODULE)`
  491. * or
  492. * `() => import('...').then(mod => mod.ROUTES)`
  493. *
  494. * For example:
  495. *
  496. * ```ts
  497. * [{
  498. * path: 'lazy',
  499. * loadChildren: () => import('./lazy-route/lazy.module').then(mod => mod.LazyModule),
  500. * }];
  501. * ```
  502. * or
  503. * ```ts
  504. * [{
  505. * path: 'lazy',
  506. * loadChildren: () => import('./lazy-route/lazy.routes').then(mod => mod.ROUTES),
  507. * }];
  508. * ```
  509. *
  510. * If the lazy-loaded routes are exported via a `default` export, the `.then` can be omitted:
  511. * ```ts
  512. * [{
  513. * path: 'lazy',
  514. * loadChildren: () => import('./lazy-route/lazy.routes'),
  515. * }];
  516. * ```
  517. *
  518. * @see {@link Route#loadChildren}
  519. * @publicApi
  520. */
  521. type LoadChildrenCallback = () => Type<any> | NgModuleFactory<any> | Routes | Observable<Type<any> | Routes | DefaultExport<Type<any>> | DefaultExport<Routes>> | Promise<NgModuleFactory<any> | Type<any> | Routes | DefaultExport<Type<any>> | DefaultExport<Routes>>;
  522. /**
  523. *
  524. * A function that returns a set of routes to load.
  525. *
  526. * @see {@link LoadChildrenCallback}
  527. * @publicApi
  528. */
  529. type LoadChildren = LoadChildrenCallback;
  530. /**
  531. *
  532. * How to handle query parameters in a router link.
  533. * One of:
  534. * - `"merge"` : Merge new parameters with current parameters.
  535. * - `"preserve"` : Preserve current parameters.
  536. * - `"replace"` : Replace current parameters with new parameters. This is the default behavior.
  537. * - `""` : For legacy reasons, the same as `'replace'`.
  538. *
  539. * @see {@link UrlCreationOptions#queryParamsHandling}
  540. * @see {@link RouterLink}
  541. * @publicApi
  542. */
  543. type QueryParamsHandling = 'merge' | 'preserve' | 'replace' | '';
  544. /**
  545. * The type for the function that can be used to handle redirects when the path matches a `Route` config.
  546. *
  547. * The `RedirectFunction` does have access to the full
  548. * `ActivatedRouteSnapshot` interface. Some data are not accurately known
  549. * at the route matching phase. For example, resolvers are not run until
  550. * later, so any resolved title would not be populated. The same goes for lazy
  551. * loaded components. This is also true for all the snapshots up to the
  552. * root, so properties that include parents (root, parent, pathFromRoot)
  553. * are also excluded. And naturally, the full route matching hasn't yet
  554. * happened so firstChild and children are not available either.
  555. *
  556. * @see {@link Route#redirectTo}
  557. * @publicApi
  558. */
  559. type RedirectFunction = (redirectData: Pick<ActivatedRouteSnapshot, 'routeConfig' | 'url' | 'params' | 'queryParams' | 'fragment' | 'data' | 'outlet' | 'title'>) => string | UrlTree;
  560. /**
  561. * A policy for when to run guards and resolvers on a route.
  562. *
  563. * Guards and/or resolvers will always run when a route is activated or deactivated. When a route is
  564. * unchanged, the default behavior is the same as `paramsChange`.
  565. *
  566. * `paramsChange` : Rerun the guards and resolvers when path or
  567. * path param changes. This does not include query parameters. This option is the default.
  568. * - `always` : Run on every execution.
  569. * - `pathParamsChange` : Rerun guards and resolvers when the path params
  570. * change. This does not compare matrix or query parameters.
  571. * - `paramsOrQueryParamsChange` : Run when path, matrix, or query parameters change.
  572. * - `pathParamsOrQueryParamsChange` : Rerun guards and resolvers when the path params
  573. * change or query params have changed. This does not include matrix parameters.
  574. *
  575. * @see {@link Route#runGuardsAndResolvers}
  576. * @publicApi
  577. */
  578. type RunGuardsAndResolvers = 'pathParamsChange' | 'pathParamsOrQueryParamsChange' | 'paramsChange' | 'paramsOrQueryParamsChange' | 'always' | ((from: ActivatedRouteSnapshot, to: ActivatedRouteSnapshot) => boolean);
  579. /**
  580. * A configuration object that defines a single route.
  581. * A set of routes are collected in a `Routes` array to define a `Router` configuration.
  582. * The router attempts to match segments of a given URL against each route,
  583. * using the configuration options defined in this object.
  584. *
  585. * Supports static, parameterized, redirect, and wildcard routes, as well as
  586. * custom route data and resolve methods.
  587. *
  588. * For detailed usage information, see the [Routing Guide](guide/routing/common-router-tasks).
  589. *
  590. * @usageNotes
  591. *
  592. * ### Simple Configuration
  593. *
  594. * The following route specifies that when navigating to, for example,
  595. * `/team/11/user/bob`, the router creates the 'Team' component
  596. * with the 'User' child component in it.
  597. *
  598. * ```ts
  599. * [{
  600. * path: 'team/:id',
  601. * component: Team,
  602. * children: [{
  603. * path: 'user/:name',
  604. * component: User
  605. * }]
  606. * }]
  607. * ```
  608. *
  609. * ### Multiple Outlets
  610. *
  611. * The following route creates sibling components with multiple outlets.
  612. * When navigating to `/team/11(aux:chat/jim)`, the router creates the 'Team' component next to
  613. * the 'Chat' component. The 'Chat' component is placed into the 'aux' outlet.
  614. *
  615. * ```ts
  616. * [{
  617. * path: 'team/:id',
  618. * component: Team
  619. * }, {
  620. * path: 'chat/:user',
  621. * component: Chat
  622. * outlet: 'aux'
  623. * }]
  624. * ```
  625. *
  626. * ### Wild Cards
  627. *
  628. * The following route uses wild-card notation to specify a component
  629. * that is always instantiated regardless of where you navigate to.
  630. *
  631. * ```ts
  632. * [{
  633. * path: '**',
  634. * component: WildcardComponent
  635. * }]
  636. * ```
  637. *
  638. * ### Redirects
  639. *
  640. * The following route uses the `redirectTo` property to ignore a segment of
  641. * a given URL when looking for a child path.
  642. *
  643. * When navigating to '/team/11/legacy/user/jim', the router changes the URL segment
  644. * '/team/11/legacy/user/jim' to '/team/11/user/jim', and then instantiates
  645. * the Team component with the User child component in it.
  646. *
  647. * ```ts
  648. * [{
  649. * path: 'team/:id',
  650. * component: Team,
  651. * children: [{
  652. * path: 'legacy/user/:name',
  653. * redirectTo: 'user/:name'
  654. * }, {
  655. * path: 'user/:name',
  656. * component: User
  657. * }]
  658. * }]
  659. * ```
  660. *
  661. * The redirect path can be relative, as shown in this example, or absolute.
  662. * If we change the `redirectTo` value in the example to the absolute URL segment '/user/:name',
  663. * the result URL is also absolute, '/user/jim'.
  664. * ### Empty Path
  665. *
  666. * Empty-path route configurations can be used to instantiate components that do not 'consume'
  667. * any URL segments.
  668. *
  669. * In the following configuration, when navigating to
  670. * `/team/11`, the router instantiates the 'AllUsers' component.
  671. *
  672. * ```ts
  673. * [{
  674. * path: 'team/:id',
  675. * component: Team,
  676. * children: [{
  677. * path: '',
  678. * component: AllUsers
  679. * }, {
  680. * path: 'user/:name',
  681. * component: User
  682. * }]
  683. * }]
  684. * ```
  685. *
  686. * Empty-path routes can have children. In the following example, when navigating
  687. * to `/team/11/user/jim`, the router instantiates the wrapper component with
  688. * the user component in it.
  689. *
  690. * Note that an empty path route inherits its parent's parameters and data.
  691. *
  692. * ```ts
  693. * [{
  694. * path: 'team/:id',
  695. * component: Team,
  696. * children: [{
  697. * path: '',
  698. * component: WrapperCmp,
  699. * children: [{
  700. * path: 'user/:name',
  701. * component: User
  702. * }]
  703. * }]
  704. * }]
  705. * ```
  706. *
  707. * ### Matching Strategy
  708. *
  709. * The default path-match strategy is 'prefix', which means that the router
  710. * checks URL elements from the left to see if the URL matches a specified path.
  711. * For example, '/team/11/user' matches 'team/:id'.
  712. *
  713. * ```ts
  714. * [{
  715. * path: '',
  716. * pathMatch: 'prefix', //default
  717. * redirectTo: 'main'
  718. * }, {
  719. * path: 'main',
  720. * component: Main
  721. * }]
  722. * ```
  723. *
  724. * You can specify the path-match strategy 'full' to make sure that the path
  725. * covers the whole unconsumed URL. It is important to do this when redirecting
  726. * empty-path routes. Otherwise, because an empty path is a prefix of any URL,
  727. * the router would apply the redirect even when navigating to the redirect destination,
  728. * creating an endless loop.
  729. *
  730. * In the following example, supplying the 'full' `pathMatch` strategy ensures
  731. * that the router applies the redirect if and only if navigating to '/'.
  732. *
  733. * ```ts
  734. * [{
  735. * path: '',
  736. * pathMatch: 'full',
  737. * redirectTo: 'main'
  738. * }, {
  739. * path: 'main',
  740. * component: Main
  741. * }]
  742. * ```
  743. *
  744. * ### Componentless Routes
  745. *
  746. * You can share parameters between sibling components.
  747. * For example, suppose that two sibling components should go next to each other,
  748. * and both of them require an ID parameter. You can accomplish this using a route
  749. * that does not specify a component at the top level.
  750. *
  751. * In the following example, 'MainChild' and 'AuxChild' are siblings.
  752. * When navigating to 'parent/10/(a//aux:b)', the route instantiates
  753. * the main child and aux child components next to each other.
  754. * For this to work, the application component must have the primary and aux outlets defined.
  755. *
  756. * ```ts
  757. * [{
  758. * path: 'parent/:id',
  759. * children: [
  760. * { path: 'a', component: MainChild },
  761. * { path: 'b', component: AuxChild, outlet: 'aux' }
  762. * ]
  763. * }]
  764. * ```
  765. *
  766. * The router merges the parameters, data, and resolve of the componentless
  767. * parent into the parameters, data, and resolve of the children.
  768. *
  769. * This is especially useful when child components are defined
  770. * with an empty path string, as in the following example.
  771. * With this configuration, navigating to '/parent/10' creates
  772. * the main child and aux components.
  773. *
  774. * ```ts
  775. * [{
  776. * path: 'parent/:id',
  777. * children: [
  778. * { path: '', component: MainChild },
  779. * { path: '', component: AuxChild, outlet: 'aux' }
  780. * ]
  781. * }]
  782. * ```
  783. *
  784. * ### Lazy Loading
  785. *
  786. * Lazy loading speeds up application load time by splitting the application
  787. * into multiple bundles and loading them on demand.
  788. * To use lazy loading, provide the `loadChildren` property in the `Route` object,
  789. * instead of the `children` property.
  790. *
  791. * Given the following example route, the router will lazy load
  792. * the associated module on demand using the browser native import system.
  793. *
  794. * ```ts
  795. * [{
  796. * path: 'lazy',
  797. * loadChildren: () => import('./lazy-route/lazy.module').then(mod => mod.LazyModule),
  798. * }];
  799. * ```
  800. *
  801. * @publicApi
  802. */
  803. interface Route {
  804. /**
  805. * Used to define a page title for the route. This can be a static string or an `Injectable` that
  806. * implements `Resolve`.
  807. *
  808. * @see {@link TitleStrategy}
  809. */
  810. title?: string | Type<Resolve<string>> | ResolveFn<string>;
  811. /**
  812. * The path to match against. Cannot be used together with a custom `matcher` function.
  813. * A URL string that uses router matching notation.
  814. * Can be a wild card (`**`) that matches any URL (see Usage Notes below).
  815. * Default is "/" (the root path).
  816. *
  817. */
  818. path?: string;
  819. /**
  820. * The path-matching strategy, one of 'prefix' or 'full'.
  821. * Default is 'prefix'.
  822. *
  823. * By default, the router checks URL elements from the left to see if the URL
  824. * matches a given path and stops when there is a config match. Importantly there must still be a
  825. * config match for each segment of the URL. For example, '/team/11/user' matches the prefix
  826. * 'team/:id' if one of the route's children matches the segment 'user'. That is, the URL
  827. * '/team/11/user' matches the config
  828. * `{path: 'team/:id', children: [{path: ':user', component: User}]}`
  829. * but does not match when there are no children as in `{path: 'team/:id', component: Team}`.
  830. *
  831. * The path-match strategy 'full' matches against the entire URL.
  832. * It is important to do this when redirecting empty-path routes.
  833. * Otherwise, because an empty path is a prefix of any URL,
  834. * the router would apply the redirect even when navigating
  835. * to the redirect destination, creating an endless loop.
  836. *
  837. */
  838. pathMatch?: 'prefix' | 'full';
  839. /**
  840. * A custom URL-matching function. Cannot be used together with `path`.
  841. */
  842. matcher?: UrlMatcher;
  843. /**
  844. * The component to instantiate when the path matches.
  845. * Can be empty if child routes specify components.
  846. */
  847. component?: Type<any>;
  848. /**
  849. * An object specifying a lazy-loaded component.
  850. */
  851. loadComponent?: () => Type<unknown> | Observable<Type<unknown> | DefaultExport<Type<unknown>>> | Promise<Type<unknown> | DefaultExport<Type<unknown>>>;
  852. /**
  853. * A URL or function that returns a URL to redirect to when the path matches.
  854. *
  855. * Absolute if the URL begins with a slash (/) or the function returns a `UrlTree`, otherwise
  856. * relative to the path URL.
  857. *
  858. * The `RedirectFunction` is run in an injection context so it can call `inject` to get any
  859. * required dependencies.
  860. *
  861. * When not present, router does not redirect.
  862. */
  863. redirectTo?: string | RedirectFunction;
  864. /**
  865. * Name of a `RouterOutlet` object where the component can be placed
  866. * when the path matches.
  867. */
  868. outlet?: string;
  869. /**
  870. * An array of `CanActivateFn` or DI tokens used to look up `CanActivate()`
  871. * handlers, in order to determine if the current user is allowed to
  872. * activate the component. By default, any user can activate.
  873. *
  874. * When using a function rather than DI tokens, the function can call `inject` to get any required
  875. * dependencies. This `inject` call must be done in a synchronous context.
  876. */
  877. canActivate?: Array<CanActivateFn | DeprecatedGuard>;
  878. /**
  879. * An array of `CanMatchFn` or DI tokens used to look up `CanMatch()`
  880. * handlers, in order to determine if the current user is allowed to
  881. * match the `Route`. By default, any route can match.
  882. *
  883. * When using a function rather than DI tokens, the function can call `inject` to get any required
  884. * dependencies. This `inject` call must be done in a synchronous context.
  885. */
  886. canMatch?: Array<CanMatchFn | DeprecatedGuard>;
  887. /**
  888. * An array of `CanActivateChildFn` or DI tokens used to look up `CanActivateChild()` handlers,
  889. * in order to determine if the current user is allowed to activate
  890. * a child of the component. By default, any user can activate a child.
  891. *
  892. * When using a function rather than DI tokens, the function can call `inject` to get any required
  893. * dependencies. This `inject` call must be done in a synchronous context.
  894. */
  895. canActivateChild?: Array<CanActivateChildFn | DeprecatedGuard>;
  896. /**
  897. * An array of `CanDeactivateFn` or DI tokens used to look up `CanDeactivate()`
  898. * handlers, in order to determine if the current user is allowed to
  899. * deactivate the component. By default, any user can deactivate.
  900. *
  901. * When using a function rather than DI tokens, the function can call `inject` to get any required
  902. * dependencies. This `inject` call must be done in a synchronous context.
  903. */
  904. canDeactivate?: Array<CanDeactivateFn<any> | DeprecatedGuard>;
  905. /**
  906. * An array of `CanLoadFn` or DI tokens used to look up `CanLoad()`
  907. * handlers, in order to determine if the current user is allowed to
  908. * load the component. By default, any user can load.
  909. *
  910. * When using a function rather than DI tokens, the function can call `inject` to get any required
  911. * dependencies. This `inject` call must be done in a synchronous context.
  912. * @deprecated Use `canMatch` instead
  913. */
  914. canLoad?: Array<CanLoadFn | DeprecatedGuard>;
  915. /**
  916. * Additional developer-defined data provided to the component via
  917. * `ActivatedRoute`. By default, no additional data is passed.
  918. */
  919. data?: Data;
  920. /**
  921. * A map of DI tokens used to look up data resolvers. See `Resolve`.
  922. */
  923. resolve?: ResolveData;
  924. /**
  925. * An array of child `Route` objects that specifies a nested route
  926. * configuration.
  927. */
  928. children?: Routes;
  929. /**
  930. * An object specifying lazy-loaded child routes.
  931. */
  932. loadChildren?: LoadChildren;
  933. /**
  934. * A policy for when to run guards and resolvers on a route.
  935. *
  936. * Guards and/or resolvers will always run when a route is activated or deactivated. When a route
  937. * is unchanged, the default behavior is the same as `paramsChange`.
  938. *
  939. * `paramsChange` : Rerun the guards and resolvers when path or
  940. * path param changes. This does not include query parameters. This option is the default.
  941. * - `always` : Run on every execution.
  942. * - `pathParamsChange` : Rerun guards and resolvers when the path params
  943. * change. This does not compare matrix or query parameters.
  944. * - `paramsOrQueryParamsChange` : Run when path, matrix, or query parameters change.
  945. * - `pathParamsOrQueryParamsChange` : Rerun guards and resolvers when the path params
  946. * change or query params have changed. This does not include matrix parameters.
  947. *
  948. * @see {@link RunGuardsAndResolvers}
  949. */
  950. runGuardsAndResolvers?: RunGuardsAndResolvers;
  951. /**
  952. * A `Provider` array to use for this `Route` and its `children`.
  953. *
  954. * The `Router` will create a new `EnvironmentInjector` for this
  955. * `Route` and use it for this `Route` and its `children`. If this
  956. * route also has a `loadChildren` function which returns an `NgModuleRef`, this injector will be
  957. * used as the parent of the lazy loaded module.
  958. */
  959. providers?: Array<Provider | EnvironmentProviders>;
  960. }
  961. interface LoadedRouterConfig {
  962. routes: Route[];
  963. injector: EnvironmentInjector | undefined;
  964. }
  965. /**
  966. * @description
  967. *
  968. * Interface that a class can implement to be a guard deciding if a route can be activated.
  969. * If all guards return `true`, navigation continues. If any guard returns `false`,
  970. * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation
  971. * is cancelled and a new navigation begins to the `UrlTree` returned from the guard.
  972. *
  973. * The following example implements a `CanActivate` function that checks whether the
  974. * current user has permission to activate the requested route.
  975. *
  976. * ```ts
  977. * class UserToken {}
  978. * class Permissions {
  979. * canActivate(): boolean {
  980. * return true;
  981. * }
  982. * }
  983. *
  984. * @Injectable()
  985. * class CanActivateTeam implements CanActivate {
  986. * constructor(private permissions: Permissions, private currentUser: UserToken) {}
  987. *
  988. * canActivate(
  989. * route: ActivatedRouteSnapshot,
  990. * state: RouterStateSnapshot
  991. * ): MaybeAsync<GuardResult> {
  992. * return this.permissions.canActivate(this.currentUser, route.params.id);
  993. * }
  994. * }
  995. * ```
  996. *
  997. * Here, the defined guard function is provided as part of the `Route` object
  998. * in the router configuration:
  999. *
  1000. * ```ts
  1001. * @NgModule({
  1002. * imports: [
  1003. * RouterModule.forRoot([
  1004. * {
  1005. * path: 'team/:id',
  1006. * component: TeamComponent,
  1007. * canActivate: [CanActivateTeam]
  1008. * }
  1009. * ])
  1010. * ],
  1011. * providers: [CanActivateTeam, UserToken, Permissions]
  1012. * })
  1013. * class AppModule {}
  1014. * ```
  1015. *
  1016. * @publicApi
  1017. */
  1018. interface CanActivate {
  1019. canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): MaybeAsync<GuardResult>;
  1020. }
  1021. /**
  1022. * The signature of a function used as a `canActivate` guard on a `Route`.
  1023. *
  1024. * If all guards return `true`, navigation continues. If any guard returns `false`,
  1025. * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation
  1026. * is cancelled and a new navigation begins to the `UrlTree` returned from the guard.
  1027. *
  1028. * The following example implements and uses a `CanActivateFn` that checks whether the
  1029. * current user has permission to activate the requested route.
  1030. *
  1031. * ```ts
  1032. * @Injectable()
  1033. * class UserToken {}
  1034. *
  1035. * @Injectable()
  1036. * class PermissionsService {
  1037. * canActivate(currentUser: UserToken, userId: string): boolean {
  1038. * return true;
  1039. * }
  1040. * canMatch(currentUser: UserToken): boolean {
  1041. * return true;
  1042. * }
  1043. * }
  1044. *
  1045. * const canActivateTeam: CanActivateFn = (
  1046. * route: ActivatedRouteSnapshot,
  1047. * state: RouterStateSnapshot,
  1048. * ) => {
  1049. * return inject(PermissionsService).canActivate(inject(UserToken), route.params['id']);
  1050. * };
  1051. * ```
  1052. *
  1053. * Here, the defined guard function is provided as part of the `Route` object
  1054. * in the router configuration:
  1055. *
  1056. * ```ts
  1057. * bootstrapApplication(App, {
  1058. * providers: [
  1059. * provideRouter([
  1060. * {
  1061. * path: 'team/:id',
  1062. * component: TeamComponent,
  1063. * canActivate: [canActivateTeam],
  1064. * },
  1065. * ]),
  1066. * ],
  1067. * });
  1068. * ```
  1069. *
  1070. * @publicApi
  1071. * @see {@link Route}
  1072. */
  1073. type CanActivateFn = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => MaybeAsync<GuardResult>;
  1074. /**
  1075. * @description
  1076. *
  1077. * Interface that a class can implement to be a guard deciding if a child route can be activated.
  1078. * If all guards return `true`, navigation continues. If any guard returns `false`,
  1079. * navigation is cancelled. If any guard returns a `UrlTree`, current navigation
  1080. * is cancelled and a new navigation begins to the `UrlTree` returned from the guard.
  1081. *
  1082. * The following example implements a `CanActivateChild` function that checks whether the
  1083. * current user has permission to activate the requested child route.
  1084. *
  1085. * ```ts
  1086. * class UserToken {}
  1087. * class Permissions {
  1088. * canActivate(user: UserToken, id: string): boolean {
  1089. * return true;
  1090. * }
  1091. * }
  1092. *
  1093. * @Injectable()
  1094. * class CanActivateTeam implements CanActivateChild {
  1095. * constructor(private permissions: Permissions, private currentUser: UserToken) {}
  1096. *
  1097. * canActivateChild(
  1098. * route: ActivatedRouteSnapshot,
  1099. * state: RouterStateSnapshot
  1100. * ): MaybeAsync<GuardResult> {
  1101. * return this.permissions.canActivate(this.currentUser, route.params.id);
  1102. * }
  1103. * }
  1104. * ```
  1105. *
  1106. * Here, the defined guard function is provided as part of the `Route` object
  1107. * in the router configuration:
  1108. *
  1109. * ```ts
  1110. * @NgModule({
  1111. * imports: [
  1112. * RouterModule.forRoot([
  1113. * {
  1114. * path: 'root',
  1115. * canActivateChild: [CanActivateTeam],
  1116. * children: [
  1117. * {
  1118. * path: 'team/:id',
  1119. * component: TeamComponent
  1120. * }
  1121. * ]
  1122. * }
  1123. * ])
  1124. * ],
  1125. * providers: [CanActivateTeam, UserToken, Permissions]
  1126. * })
  1127. * class AppModule {}
  1128. * ```
  1129. *
  1130. * @publicApi
  1131. */
  1132. interface CanActivateChild {
  1133. canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): MaybeAsync<GuardResult>;
  1134. }
  1135. /**
  1136. * The signature of a function used as a `canActivateChild` guard on a `Route`.
  1137. *
  1138. * If all guards return `true`, navigation continues. If any guard returns `false`,
  1139. * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation
  1140. * is cancelled and a new navigation begins to the `UrlTree` returned from the guard.
  1141. *
  1142. * The following example implements a `canActivate` function that checks whether the
  1143. * current user has permission to activate the requested route.
  1144. *
  1145. * {@example router/route_functional_guards.ts region="CanActivateChildFn"}
  1146. *
  1147. * @publicApi
  1148. * @see {@link Route}
  1149. */
  1150. type CanActivateChildFn = (childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot) => MaybeAsync<GuardResult>;
  1151. /**
  1152. * @description
  1153. *
  1154. * Interface that a class can implement to be a guard deciding if a route can be deactivated.
  1155. * If all guards return `true`, navigation continues. If any guard returns `false`,
  1156. * navigation is cancelled. If any guard returns a `UrlTree`, current navigation
  1157. * is cancelled and a new navigation begins to the `UrlTree` returned from the guard.
  1158. *
  1159. * The following example implements a `CanDeactivate` function that checks whether the
  1160. * current user has permission to deactivate the requested route.
  1161. *
  1162. * ```ts
  1163. * class UserToken {}
  1164. * class Permissions {
  1165. * canDeactivate(user: UserToken, id: string): boolean {
  1166. * return true;
  1167. * }
  1168. * }
  1169. * ```
  1170. *
  1171. * Here, the defined guard function is provided as part of the `Route` object
  1172. * in the router configuration:
  1173. *
  1174. * ```ts
  1175. * @Injectable()
  1176. * class CanDeactivateTeam implements CanDeactivate<TeamComponent> {
  1177. * constructor(private permissions: Permissions, private currentUser: UserToken) {}
  1178. *
  1179. * canDeactivate(
  1180. * component: TeamComponent,
  1181. * currentRoute: ActivatedRouteSnapshot,
  1182. * currentState: RouterStateSnapshot,
  1183. * nextState: RouterStateSnapshot
  1184. * ): MaybeAsync<GuardResult> {
  1185. * return this.permissions.canDeactivate(this.currentUser, route.params.id);
  1186. * }
  1187. * }
  1188. *
  1189. * @NgModule({
  1190. * imports: [
  1191. * RouterModule.forRoot([
  1192. * {
  1193. * path: 'team/:id',
  1194. * component: TeamComponent,
  1195. * canDeactivate: [CanDeactivateTeam]
  1196. * }
  1197. * ])
  1198. * ],
  1199. * providers: [CanDeactivateTeam, UserToken, Permissions]
  1200. * })
  1201. * class AppModule {}
  1202. * ```
  1203. *
  1204. * @publicApi
  1205. */
  1206. interface CanDeactivate<T> {
  1207. canDeactivate(component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot): MaybeAsync<GuardResult>;
  1208. }
  1209. /**
  1210. * The signature of a function used as a `canDeactivate` guard on a `Route`.
  1211. *
  1212. * If all guards return `true`, navigation continues. If any guard returns `false`,
  1213. * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation
  1214. * is cancelled and a new navigation begins to the `UrlTree` returned from the guard.
  1215. *
  1216. * The following example implements and uses a `CanDeactivateFn` that checks whether the
  1217. * user component has unsaved changes before navigating away from the route.
  1218. *
  1219. * {@example router/route_functional_guards.ts region="CanDeactivateFn"}
  1220. *
  1221. * @publicApi
  1222. * @see {@link Route}
  1223. */
  1224. type CanDeactivateFn<T> = (component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot) => MaybeAsync<GuardResult>;
  1225. /**
  1226. * @description
  1227. *
  1228. * Interface that a class can implement to be a guard deciding if a `Route` can be matched.
  1229. * If all guards return `true`, navigation continues and the `Router` will use the `Route` during
  1230. * activation. If any guard returns `false`, the `Route` is skipped for matching and other `Route`
  1231. * configurations are processed instead.
  1232. *
  1233. * The following example implements a `CanMatch` function that decides whether the
  1234. * current user has permission to access the users page.
  1235. *
  1236. *
  1237. * ```ts
  1238. * class UserToken {}
  1239. * class Permissions {
  1240. * canAccess(user: UserToken, route: Route, segments: UrlSegment[]): boolean {
  1241. * return true;
  1242. * }
  1243. * }
  1244. *
  1245. * @Injectable()
  1246. * class CanMatchTeamSection implements CanMatch {
  1247. * constructor(private permissions: Permissions, private currentUser: UserToken) {}
  1248. *
  1249. * canMatch(route: Route, segments: UrlSegment[]): Observable<boolean>|Promise<boolean>|boolean {
  1250. * return this.permissions.canAccess(this.currentUser, route, segments);
  1251. * }
  1252. * }
  1253. * ```
  1254. *
  1255. * Here, the defined guard function is provided as part of the `Route` object
  1256. * in the router configuration:
  1257. *
  1258. * ```ts
  1259. * @NgModule({
  1260. * imports: [
  1261. * RouterModule.forRoot([
  1262. * {
  1263. * path: 'team/:id',
  1264. * component: TeamComponent,
  1265. * loadChildren: () => import('./team').then(mod => mod.TeamModule),
  1266. * canMatch: [CanMatchTeamSection]
  1267. * },
  1268. * {
  1269. * path: '**',
  1270. * component: NotFoundComponent
  1271. * }
  1272. * ])
  1273. * ],
  1274. * providers: [CanMatchTeamSection, UserToken, Permissions]
  1275. * })
  1276. * class AppModule {}
  1277. * ```
  1278. *
  1279. * If the `CanMatchTeamSection` were to return `false`, the router would continue navigating to the
  1280. * `team/:id` URL, but would load the `NotFoundComponent` because the `Route` for `'team/:id'`
  1281. * could not be used for a URL match but the catch-all `**` `Route` did instead.
  1282. *
  1283. * @publicApi
  1284. */
  1285. interface CanMatch {
  1286. canMatch(route: Route, segments: UrlSegment[]): MaybeAsync<GuardResult>;
  1287. }
  1288. /**
  1289. * The signature of a function used as a `canMatch` guard on a `Route`.
  1290. *
  1291. * If all guards return `true`, navigation continues and the `Router` will use the `Route` during
  1292. * activation. If any guard returns `false`, the `Route` is skipped for matching and other `Route`
  1293. * configurations are processed instead.
  1294. *
  1295. * The following example implements and uses a `CanMatchFn` that checks whether the
  1296. * current user has permission to access the team page.
  1297. *
  1298. * {@example router/route_functional_guards.ts region="CanMatchFn"}
  1299. *
  1300. * @param route The route configuration.
  1301. * @param segments The URL segments that have not been consumed by previous parent route evaluations.
  1302. *
  1303. * @publicApi
  1304. * @see {@link Route}
  1305. */
  1306. type CanMatchFn = (route: Route, segments: UrlSegment[]) => MaybeAsync<GuardResult>;
  1307. /**
  1308. * @description
  1309. *
  1310. * Interface that classes can implement to be a data provider.
  1311. * A data provider class can be used with the router to resolve data during navigation.
  1312. * The interface defines a `resolve()` method that is invoked right after the `ResolveStart`
  1313. * router event. The router waits for the data to be resolved before the route is finally activated.
  1314. *
  1315. * The following example implements a `resolve()` method that retrieves the data
  1316. * needed to activate the requested route.
  1317. *
  1318. * ```ts
  1319. * @Injectable({ providedIn: 'root' })
  1320. * export class HeroResolver implements Resolve<Hero> {
  1321. * constructor(private service: HeroService) {}
  1322. *
  1323. * resolve(
  1324. * route: ActivatedRouteSnapshot,
  1325. * state: RouterStateSnapshot
  1326. * ): Observable<Hero>|Promise<Hero>|Hero {
  1327. * return this.service.getHero(route.paramMap.get('id'));
  1328. * }
  1329. * }
  1330. * ```
  1331. *
  1332. * Here, the defined `resolve()` function is provided as part of the `Route` object
  1333. * in the router configuration:
  1334. *
  1335. * ```ts
  1336. * @NgModule({
  1337. * imports: [
  1338. * RouterModule.forRoot([
  1339. * {
  1340. * path: 'detail/:id',
  1341. * component: HeroDetailComponent,
  1342. * resolve: {
  1343. * hero: HeroResolver
  1344. * }
  1345. * }
  1346. * ])
  1347. * ],
  1348. * exports: [RouterModule]
  1349. * })
  1350. * export class AppRoutingModule {}
  1351. * ```
  1352. *
  1353. * And you can access to your resolved data from `HeroComponent`:
  1354. *
  1355. * ```ts
  1356. * @Component({
  1357. * selector: "app-hero",
  1358. * templateUrl: "hero.component.html",
  1359. * })
  1360. * export class HeroComponent {
  1361. *
  1362. * constructor(private activatedRoute: ActivatedRoute) {}
  1363. *
  1364. * ngOnInit() {
  1365. * this.activatedRoute.data.subscribe(({ hero }) => {
  1366. * // do something with your resolved data ...
  1367. * })
  1368. * }
  1369. *
  1370. * }
  1371. * ```
  1372. *
  1373. * @usageNotes
  1374. *
  1375. * When both guard and resolvers are specified, the resolvers are not executed until
  1376. * all guards have run and succeeded.
  1377. * For example, consider the following route configuration:
  1378. *
  1379. * ```ts
  1380. * {
  1381. * path: 'base'
  1382. * canActivate: [BaseGuard],
  1383. * resolve: {data: BaseDataResolver}
  1384. * children: [
  1385. * {
  1386. * path: 'child',
  1387. * guards: [ChildGuard],
  1388. * component: ChildComponent,
  1389. * resolve: {childData: ChildDataResolver}
  1390. * }
  1391. * ]
  1392. * }
  1393. * ```
  1394. * The order of execution is: BaseGuard, ChildGuard, BaseDataResolver, ChildDataResolver.
  1395. *
  1396. * @publicApi
  1397. * @see {@link ResolveFn}
  1398. */
  1399. interface Resolve<T> {
  1400. resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): MaybeAsync<T | RedirectCommand>;
  1401. }
  1402. /**
  1403. * Function type definition for a data provider.
  1404. *
  1405. * A data provider can be used with the router to resolve data during navigation.
  1406. * The router waits for the data to be resolved before the route is finally activated.
  1407. *
  1408. * A resolver can also redirect a `RedirectCommand` and the Angular router will use
  1409. * it to redirect the current navigation to the new destination.
  1410. *
  1411. * @usageNotes
  1412. *
  1413. * The following example implements a function that retrieves the data
  1414. * needed to activate the requested route.
  1415. *
  1416. * ```ts
  1417. * interface Hero {
  1418. * name: string;
  1419. * }
  1420. * @Injectable()
  1421. * export class HeroService {
  1422. * getHero(id: string) {
  1423. * return {name: `Superman-${id}`};
  1424. * }
  1425. * }
  1426. *
  1427. * export const heroResolver: ResolveFn<Hero> = (
  1428. * route: ActivatedRouteSnapshot,
  1429. * state: RouterStateSnapshot,
  1430. * ) => {
  1431. * return inject(HeroService).getHero(route.paramMap.get('id')!);
  1432. * };
  1433. *
  1434. * bootstrapApplication(App, {
  1435. * providers: [
  1436. * provideRouter([
  1437. * {
  1438. * path: 'detail/:id',
  1439. * component: HeroDetailComponent,
  1440. * resolve: {hero: heroResolver},
  1441. * },
  1442. * ]),
  1443. * ],
  1444. * });
  1445. * ```
  1446. *
  1447. * And you can access to your resolved data from `HeroComponent`:
  1448. *
  1449. * ```ts
  1450. * @Component({template: ''})
  1451. * export class HeroDetailComponent {
  1452. * private activatedRoute = inject(ActivatedRoute);
  1453. *
  1454. * ngOnInit() {
  1455. * this.activatedRoute.data.subscribe(({hero}) => {
  1456. * // do something with your resolved data ...
  1457. * });
  1458. * }
  1459. * }
  1460. * ```
  1461. *
  1462. * If resolved data cannot be retrieved, you may want to redirect the user
  1463. * to a new page instead:
  1464. *
  1465. * ```ts
  1466. * export const heroResolver: ResolveFn<Hero> = async (
  1467. * route: ActivatedRouteSnapshot,
  1468. * state: RouterStateSnapshot,
  1469. * ) => {
  1470. * const router = inject(Router);
  1471. * const heroService = inject(HeroService);
  1472. * try {
  1473. * return await heroService.getHero(route.paramMap.get('id')!);
  1474. * } catch {
  1475. * return new RedirectCommand(router.parseUrl('/404'));
  1476. * }
  1477. * };
  1478. * ```
  1479. *
  1480. * When both guard and resolvers are specified, the resolvers are not executed until
  1481. * all guards have run and succeeded.
  1482. * For example, consider the following route configuration:
  1483. *
  1484. * ```ts
  1485. * {
  1486. * path: 'base'
  1487. * canActivate: [baseGuard],
  1488. * resolve: {data: baseDataResolver}
  1489. * children: [
  1490. * {
  1491. * path: 'child',
  1492. * canActivate: [childGuard],
  1493. * component: ChildComponent,
  1494. * resolve: {childData: childDataResolver}
  1495. * }
  1496. * ]
  1497. * }
  1498. * ```
  1499. * The order of execution is: baseGuard, childGuard, baseDataResolver, childDataResolver.
  1500. *
  1501. * @publicApi
  1502. * @see {@link Route}
  1503. */
  1504. type ResolveFn<T> = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => MaybeAsync<T | RedirectCommand>;
  1505. /**
  1506. * @description
  1507. *
  1508. * Interface that a class can implement to be a guard deciding if children can be loaded.
  1509. * If all guards return `true`, navigation continues. If any guard returns `false`,
  1510. * navigation is cancelled. If any guard returns a `UrlTree`, current navigation
  1511. * is cancelled and a new navigation starts to the `UrlTree` returned from the guard.
  1512. *
  1513. * The following example implements a `CanLoad` function that decides whether the
  1514. * current user has permission to load requested child routes.
  1515. *
  1516. *
  1517. * ```ts
  1518. * class UserToken {}
  1519. * class Permissions {
  1520. * canLoadChildren(user: UserToken, id: string, segments: UrlSegment[]): boolean {
  1521. * return true;
  1522. * }
  1523. * }
  1524. *
  1525. * @Injectable()
  1526. * class CanLoadTeamSection implements CanLoad {
  1527. * constructor(private permissions: Permissions, private currentUser: UserToken) {}
  1528. *
  1529. * canLoad(route: Route, segments: UrlSegment[]): Observable<boolean>|Promise<boolean>|boolean {
  1530. * return this.permissions.canLoadChildren(this.currentUser, route, segments);
  1531. * }
  1532. * }
  1533. * ```
  1534. *
  1535. * Here, the defined guard function is provided as part of the `Route` object
  1536. * in the router configuration:
  1537. *
  1538. * ```ts
  1539. * @NgModule({
  1540. * imports: [
  1541. * RouterModule.forRoot([
  1542. * {
  1543. * path: 'team/:id',
  1544. * component: TeamComponent,
  1545. * loadChildren: () => import('./team').then(mod => mod.TeamModule),
  1546. * canLoad: [CanLoadTeamSection]
  1547. * }
  1548. * ])
  1549. * ],
  1550. * providers: [CanLoadTeamSection, UserToken, Permissions]
  1551. * })
  1552. * class AppModule {}
  1553. * ```
  1554. *
  1555. * @publicApi
  1556. * @deprecated Use {@link CanMatch} instead
  1557. */
  1558. interface CanLoad {
  1559. canLoad(route: Route, segments: UrlSegment[]): MaybeAsync<GuardResult>;
  1560. }
  1561. /**
  1562. * The signature of a function used as a `canLoad` guard on a `Route`.
  1563. *
  1564. * @publicApi
  1565. * @see {@link CanLoad}
  1566. * @see {@link Route}
  1567. * @see {@link CanMatch}
  1568. * @deprecated Use `Route.canMatch` and `CanMatchFn` instead
  1569. */
  1570. type CanLoadFn = (route: Route, segments: UrlSegment[]) => MaybeAsync<GuardResult>;
  1571. /**
  1572. * @description
  1573. *
  1574. * Options that modify the `Router` navigation strategy.
  1575. * Supply an object containing any of these properties to a `Router` navigation function to
  1576. * control how the navigation should be handled.
  1577. *
  1578. * @see {@link Router#navigate}
  1579. * @see {@link Router#navigateByUrl}
  1580. * @see [Routing and Navigation guide](guide/routing/common-router-tasks)
  1581. *
  1582. * @publicApi
  1583. */
  1584. interface NavigationBehaviorOptions {
  1585. /**
  1586. * How to handle a navigation request to the current URL.
  1587. *
  1588. * This value is a subset of the options available in `OnSameUrlNavigation` and
  1589. * will take precedence over the default value set for the `Router`.
  1590. *
  1591. * @see {@link OnSameUrlNavigation}
  1592. * @see {@link RouterConfigOptions}
  1593. */
  1594. onSameUrlNavigation?: OnSameUrlNavigation;
  1595. /**
  1596. * When true, navigates without pushing a new state into history.
  1597. *
  1598. * ```
  1599. * // Navigate silently to /view
  1600. * this.router.navigate(['/view'], { skipLocationChange: true });
  1601. * ```
  1602. */
  1603. skipLocationChange?: boolean;
  1604. /**
  1605. * When true, navigates while replacing the current state in history.
  1606. *
  1607. * ```
  1608. * // Navigate to /view
  1609. * this.router.navigate(['/view'], { replaceUrl: true });
  1610. * ```
  1611. */
  1612. replaceUrl?: boolean;
  1613. /**
  1614. * Developer-defined state that can be passed to any navigation.
  1615. * Access this value through the `Navigation.extras` object
  1616. * returned from the [Router.getCurrentNavigation()
  1617. * method](api/router/Router#getcurrentnavigation) while a navigation is executing.
  1618. *
  1619. * After a navigation completes, the router writes an object containing this
  1620. * value together with a `navigationId` to `history.state`.
  1621. * The value is written when `location.go()` or `location.replaceState()`
  1622. * is called before activating this route.
  1623. *
  1624. * Note that `history.state` does not pass an object equality test because
  1625. * the router adds the `navigationId` on each navigation.
  1626. *
  1627. */
  1628. state?: {
  1629. [k: string]: any;
  1630. };
  1631. /**
  1632. * Use this to convey transient information about this particular navigation, such as how it
  1633. * happened. In this way, it's different from the persisted value `state` that will be set to
  1634. * `history.state`. This object is assigned directly to the Router's current `Navigation`
  1635. * (it is not copied or cloned), so it should be mutated with caution.
  1636. *
  1637. * One example of how this might be used is to trigger different single-page navigation animations
  1638. * depending on how a certain route was reached. For example, consider a photo gallery app, where
  1639. * you can reach the same photo URL and state via various routes:
  1640. *
  1641. * - Clicking on it in a gallery view
  1642. * - Clicking
  1643. * - "next" or "previous" when viewing another photo in the album
  1644. * - Etc.
  1645. *
  1646. * Each of these wants a different animation at navigate time. This information doesn't make sense
  1647. * to store in the persistent URL or history entry state, but it's still important to communicate
  1648. * from the rest of the application, into the router.
  1649. *
  1650. * This information could be used in coordination with the View Transitions feature and the
  1651. * `onViewTransitionCreated` callback. The information might be used in the callback to set
  1652. * classes on the document in order to control the transition animations and remove the classes
  1653. * when the transition has finished animating.
  1654. */
  1655. readonly info?: unknown;
  1656. /**
  1657. * When set, the Router will update the browser's address bar to match the given `UrlTree` instead
  1658. * of the one used for route matching.
  1659. *
  1660. *
  1661. * @usageNotes
  1662. *
  1663. * This feature is useful for redirects, such as redirecting to an error page, without changing
  1664. * the value that will be displayed in the browser's address bar.
  1665. *
  1666. * ```ts
  1667. * const canActivate: CanActivateFn = (route: ActivatedRouteSnapshot) => {
  1668. * const userService = inject(UserService);
  1669. * const router = inject(Router);
  1670. * if (!userService.isLoggedIn()) {
  1671. * const targetOfCurrentNavigation = router.getCurrentNavigation()?.finalUrl;
  1672. * const redirect = router.parseUrl('/404');
  1673. * return new RedirectCommand(redirect, {browserUrl: targetOfCurrentNavigation});
  1674. * }
  1675. * return true;
  1676. * };
  1677. * ```
  1678. *
  1679. * This value is used directly, without considering any `UrlHandingStrategy`. In this way,
  1680. * `browserUrl` can also be used to use a different value for the browser URL than what would have
  1681. * been produced by from the navigation due to `UrlHandlingStrategy.merge`.
  1682. *
  1683. * This value only affects the path presented in the browser's address bar. It does not apply to
  1684. * the internal `Router` state. Information such as `params` and `data` will match the internal
  1685. * state used to match routes which will be different from the browser URL when using this feature
  1686. * The same is true when using other APIs that cause the browser URL the differ from the Router
  1687. * state, such as `skipLocationChange`.
  1688. */
  1689. readonly browserUrl?: UrlTree | string;
  1690. }
  1691. declare class Tree<T> {
  1692. constructor(root: TreeNode<T>);
  1693. get root(): T;
  1694. }
  1695. declare class TreeNode<T> {
  1696. value: T;
  1697. children: TreeNode<T>[];
  1698. constructor(value: T, children: TreeNode<T>[]);
  1699. toString(): string;
  1700. }
  1701. /**
  1702. * Represents the state of the router as a tree of activated routes.
  1703. *
  1704. * @usageNotes
  1705. *
  1706. * Every node in the route tree is an `ActivatedRoute` instance
  1707. * that knows about the "consumed" URL segments, the extracted parameters,
  1708. * and the resolved data.
  1709. * Use the `ActivatedRoute` properties to traverse the tree from any node.
  1710. *
  1711. * The following fragment shows how a component gets the root node
  1712. * of the current state to establish its own route tree:
  1713. *
  1714. * ```ts
  1715. * @Component({templateUrl:'template.html'})
  1716. * class MyComponent {
  1717. * constructor(router: Router) {
  1718. * const state: RouterState = router.routerState;
  1719. * const root: ActivatedRoute = state.root;
  1720. * const child = root.firstChild;
  1721. * const id: Observable<string> = child.params.map(p => p.id);
  1722. * //...
  1723. * }
  1724. * }
  1725. * ```
  1726. *
  1727. * @see {@link ActivatedRoute}
  1728. * @see [Getting route information](guide/routing/common-router-tasks#getting-route-information)
  1729. *
  1730. * @publicApi
  1731. */
  1732. declare class RouterState extends Tree<ActivatedRoute> {
  1733. /** The current snapshot of the router state */
  1734. snapshot: RouterStateSnapshot;
  1735. toString(): string;
  1736. }
  1737. /**
  1738. * Provides access to information about a route associated with a component
  1739. * that is loaded in an outlet.
  1740. * Use to traverse the `RouterState` tree and extract information from nodes.
  1741. *
  1742. * The following example shows how to construct a component using information from a
  1743. * currently activated route.
  1744. *
  1745. * Note: the observables in this class only emit when the current and previous values differ based
  1746. * on shallow equality. For example, changing deeply nested properties in resolved `data` will not
  1747. * cause the `ActivatedRoute.data` `Observable` to emit a new value.
  1748. *
  1749. * {@example router/activated-route/module.ts region="activated-route"
  1750. * header="activated-route.component.ts"}
  1751. *
  1752. * @see [Getting route information](guide/routing/common-router-tasks#getting-route-information)
  1753. *
  1754. * @publicApi
  1755. */
  1756. declare class ActivatedRoute {
  1757. /** The outlet name of the route, a constant. */
  1758. outlet: string;
  1759. /** The component of the route, a constant. */
  1760. component: Type<any> | null;
  1761. /** The current snapshot of this route */
  1762. snapshot: ActivatedRouteSnapshot;
  1763. /** An Observable of the resolved route title */
  1764. readonly title: Observable<string | undefined>;
  1765. /** An observable of the URL segments matched by this route. */
  1766. url: Observable<UrlSegment[]>;
  1767. /** An observable of the matrix parameters scoped to this route. */
  1768. params: Observable<Params>;
  1769. /** An observable of the query parameters shared by all the routes. */
  1770. queryParams: Observable<Params>;
  1771. /** An observable of the URL fragment shared by all the routes. */
  1772. fragment: Observable<string | null>;
  1773. /** An observable of the static and resolved data of this route. */
  1774. data: Observable<Data>;
  1775. /** The configuration used to match this route. */
  1776. get routeConfig(): Route | null;
  1777. /** The root of the router state. */
  1778. get root(): ActivatedRoute;
  1779. /** The parent of this route in the router state tree. */
  1780. get parent(): ActivatedRoute | null;
  1781. /** The first child of this route in the router state tree. */
  1782. get firstChild(): ActivatedRoute | null;
  1783. /** The children of this route in the router state tree. */
  1784. get children(): ActivatedRoute[];
  1785. /** The path from the root of the router state tree to this route. */
  1786. get pathFromRoot(): ActivatedRoute[];
  1787. /**
  1788. * An Observable that contains a map of the required and optional parameters
  1789. * specific to the route.
  1790. * The map supports retrieving single and multiple values from the same parameter.
  1791. */
  1792. get paramMap(): Observable<ParamMap>;
  1793. /**
  1794. * An Observable that contains a map of the query parameters available to all routes.
  1795. * The map supports retrieving single and multiple values from the query parameter.
  1796. */
  1797. get queryParamMap(): Observable<ParamMap>;
  1798. toString(): string;
  1799. }
  1800. /**
  1801. * @description
  1802. *
  1803. * Contains the information about a route associated with a component loaded in an
  1804. * outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to
  1805. * traverse the router state tree.
  1806. *
  1807. * The following example initializes a component with route information extracted
  1808. * from the snapshot of the root node at the time of creation.
  1809. *
  1810. * ```ts
  1811. * @Component({templateUrl:'./my-component.html'})
  1812. * class MyComponent {
  1813. * constructor(route: ActivatedRoute) {
  1814. * const id: string = route.snapshot.params.id;
  1815. * const url: string = route.snapshot.url.join('');
  1816. * const user = route.snapshot.data.user;
  1817. * }
  1818. * }
  1819. * ```
  1820. *
  1821. * @publicApi
  1822. */
  1823. declare class ActivatedRouteSnapshot {
  1824. /** The URL segments matched by this route */
  1825. url: UrlSegment[];
  1826. /**
  1827. * The matrix parameters scoped to this route.
  1828. *
  1829. * You can compute all params (or data) in the router state or to get params outside
  1830. * of an activated component by traversing the `RouterState` tree as in the following
  1831. * example:
  1832. * ```ts
  1833. * collectRouteParams(router: Router) {
  1834. * let params = {};
  1835. * let stack: ActivatedRouteSnapshot[] = [router.routerState.snapshot.root];
  1836. * while (stack.length > 0) {
  1837. * const route = stack.pop()!;
  1838. * params = {...params, ...route.params};
  1839. * stack.push(...route.children);
  1840. * }
  1841. * return params;
  1842. * }
  1843. * ```
  1844. */
  1845. params: Params;
  1846. /** The query parameters shared by all the routes */
  1847. queryParams: Params;
  1848. /** The URL fragment shared by all the routes */
  1849. fragment: string | null;
  1850. /** The static and resolved data of this route */
  1851. data: Data;
  1852. /** The outlet name of the route */
  1853. outlet: string;
  1854. /** The component of the route */
  1855. component: Type<any> | null;
  1856. /** The configuration used to match this route **/
  1857. readonly routeConfig: Route | null;
  1858. /** The resolved route title */
  1859. get title(): string | undefined;
  1860. /** The root of the router state */
  1861. get root(): ActivatedRouteSnapshot;
  1862. /** The parent of this route in the router state tree */
  1863. get parent(): ActivatedRouteSnapshot | null;
  1864. /** The first child of this route in the router state tree */
  1865. get firstChild(): ActivatedRouteSnapshot | null;
  1866. /** The children of this route in the router state tree */
  1867. get children(): ActivatedRouteSnapshot[];
  1868. /** The path from the root of the router state tree to this route */
  1869. get pathFromRoot(): ActivatedRouteSnapshot[];
  1870. get paramMap(): ParamMap;
  1871. get queryParamMap(): ParamMap;
  1872. toString(): string;
  1873. }
  1874. /**
  1875. * @description
  1876. *
  1877. * Represents the state of the router at a moment in time.
  1878. *
  1879. * This is a tree of activated route snapshots. Every node in this tree knows about
  1880. * the "consumed" URL segments, the extracted parameters, and the resolved data.
  1881. *
  1882. * The following example shows how a component is initialized with information
  1883. * from the snapshot of the root node's state at the time of creation.
  1884. *
  1885. * ```ts
  1886. * @Component({templateUrl:'template.html'})
  1887. * class MyComponent {
  1888. * constructor(router: Router) {
  1889. * const state: RouterState = router.routerState;
  1890. * const snapshot: RouterStateSnapshot = state.snapshot;
  1891. * const root: ActivatedRouteSnapshot = snapshot.root;
  1892. * const child = root.firstChild;
  1893. * const id: Observable<string> = child.params.map(p => p.id);
  1894. * //...
  1895. * }
  1896. * }
  1897. * ```
  1898. *
  1899. * @publicApi
  1900. */
  1901. declare class RouterStateSnapshot extends Tree<ActivatedRouteSnapshot> {
  1902. /** The url from which this snapshot was created */
  1903. url: string;
  1904. toString(): string;
  1905. }
  1906. /**
  1907. * Creates a `UrlTree` relative to an `ActivatedRouteSnapshot`.
  1908. *
  1909. * @publicApi
  1910. *
  1911. *
  1912. * @param relativeTo The `ActivatedRouteSnapshot` to apply the commands to
  1913. * @param commands An array of URL fragments with which to construct the new URL tree.
  1914. * If the path is static, can be the literal URL string. For a dynamic path, pass an array of path
  1915. * segments, followed by the parameters for each segment.
  1916. * The fragments are applied to the one provided in the `relativeTo` parameter.
  1917. * @param queryParams The query parameters for the `UrlTree`. `null` if the `UrlTree` does not have
  1918. * any query parameters.
  1919. * @param fragment The fragment for the `UrlTree`. `null` if the `UrlTree` does not have a fragment.
  1920. *
  1921. * @usageNotes
  1922. *
  1923. * ```ts
  1924. * // create /team/33/user/11
  1925. * createUrlTreeFromSnapshot(snapshot, ['/team', 33, 'user', 11]);
  1926. *
  1927. * // create /team/33;expand=true/user/11
  1928. * createUrlTreeFromSnapshot(snapshot, ['/team', 33, {expand: true}, 'user', 11]);
  1929. *
  1930. * // you can collapse static segments like this (this works only with the first passed-in value):
  1931. * createUrlTreeFromSnapshot(snapshot, ['/team/33/user', userId]);
  1932. *
  1933. * // If the first segment can contain slashes, and you do not want the router to split it,
  1934. * // you can do the following:
  1935. * createUrlTreeFromSnapshot(snapshot, [{segmentPath: '/one/two'}]);
  1936. *
  1937. * // create /team/33/(user/11//right:chat)
  1938. * createUrlTreeFromSnapshot(snapshot, ['/team', 33, {outlets: {primary: 'user/11', right:
  1939. * 'chat'}}], null, null);
  1940. *
  1941. * // remove the right secondary node
  1942. * createUrlTreeFromSnapshot(snapshot, ['/team', 33, {outlets: {primary: 'user/11', right: null}}]);
  1943. *
  1944. * // For the examples below, assume the current URL is for the `/team/33/user/11` and the
  1945. * `ActivatedRouteSnapshot` points to `user/11`:
  1946. *
  1947. * // navigate to /team/33/user/11/details
  1948. * createUrlTreeFromSnapshot(snapshot, ['details']);
  1949. *
  1950. * // navigate to /team/33/user/22
  1951. * createUrlTreeFromSnapshot(snapshot, ['../22']);
  1952. *
  1953. * // navigate to /team/44/user/22
  1954. * createUrlTreeFromSnapshot(snapshot, ['../../team/44/user/22']);
  1955. * ```
  1956. */
  1957. declare function createUrlTreeFromSnapshot(relativeTo: ActivatedRouteSnapshot, commands: any[], queryParams?: Params | null, fragment?: string | null): UrlTree;
  1958. /**
  1959. * Identifies the call or event that triggered a navigation.
  1960. *
  1961. * * 'imperative': Triggered by `router.navigateByUrl()` or `router.navigate()`.
  1962. * * 'popstate' : Triggered by a `popstate` event.
  1963. * * 'hashchange'-: Triggered by a `hashchange` event.
  1964. *
  1965. * @publicApi
  1966. */
  1967. type NavigationTrigger = 'imperative' | 'popstate' | 'hashchange';
  1968. /**
  1969. * Identifies the type of a router event.
  1970. *
  1971. * @publicApi
  1972. */
  1973. declare enum EventType {
  1974. NavigationStart = 0,
  1975. NavigationEnd = 1,
  1976. NavigationCancel = 2,
  1977. NavigationError = 3,
  1978. RoutesRecognized = 4,
  1979. ResolveStart = 5,
  1980. ResolveEnd = 6,
  1981. GuardsCheckStart = 7,
  1982. GuardsCheckEnd = 8,
  1983. RouteConfigLoadStart = 9,
  1984. RouteConfigLoadEnd = 10,
  1985. ChildActivationStart = 11,
  1986. ChildActivationEnd = 12,
  1987. ActivationStart = 13,
  1988. ActivationEnd = 14,
  1989. Scroll = 15,
  1990. NavigationSkipped = 16
  1991. }
  1992. /**
  1993. * Base for events the router goes through, as opposed to events tied to a specific
  1994. * route. Fired one time for any given navigation.
  1995. *
  1996. * The following code shows how a class subscribes to router events.
  1997. *
  1998. * ```ts
  1999. * import {Event, RouterEvent, Router} from '@angular/router';
  2000. *
  2001. * class MyService {
  2002. * constructor(public router: Router) {
  2003. * router.events.pipe(
  2004. * filter((e: Event | RouterEvent): e is RouterEvent => e instanceof RouterEvent)
  2005. * ).subscribe((e: RouterEvent) => {
  2006. * // Do something
  2007. * });
  2008. * }
  2009. * }
  2010. * ```
  2011. *
  2012. * @see {@link Event}
  2013. * @see [Router events summary](guide/routing/router-reference#router-events)
  2014. * @publicApi
  2015. */
  2016. declare class RouterEvent {
  2017. /** A unique ID that the router assigns to every router navigation. */
  2018. id: number;
  2019. /** The URL that is the destination for this navigation. */
  2020. url: string;
  2021. constructor(
  2022. /** A unique ID that the router assigns to every router navigation. */
  2023. id: number,
  2024. /** The URL that is the destination for this navigation. */
  2025. url: string);
  2026. }
  2027. /**
  2028. * An event triggered when a navigation starts.
  2029. *
  2030. * @publicApi
  2031. */
  2032. declare class NavigationStart extends RouterEvent {
  2033. readonly type = EventType.NavigationStart;
  2034. /**
  2035. * Identifies the call or event that triggered the navigation.
  2036. * An `imperative` trigger is a call to `router.navigateByUrl()` or `router.navigate()`.
  2037. *
  2038. * @see {@link NavigationEnd}
  2039. * @see {@link NavigationCancel}
  2040. * @see {@link NavigationError}
  2041. */
  2042. navigationTrigger?: NavigationTrigger;
  2043. /**
  2044. * The navigation state that was previously supplied to the `pushState` call,
  2045. * when the navigation is triggered by a `popstate` event. Otherwise null.
  2046. *
  2047. * The state object is defined by `NavigationExtras`, and contains any
  2048. * developer-defined state value, as well as a unique ID that
  2049. * the router assigns to every router transition/navigation.
  2050. *
  2051. * From the perspective of the router, the router never "goes back".
  2052. * When the user clicks on the back button in the browser,
  2053. * a new navigation ID is created.
  2054. *
  2055. * Use the ID in this previous-state object to differentiate between a newly created
  2056. * state and one returned to by a `popstate` event, so that you can restore some
  2057. * remembered state, such as scroll position.
  2058. *
  2059. */
  2060. restoredState?: {
  2061. [k: string]: any;
  2062. navigationId: number;
  2063. } | null;
  2064. constructor(
  2065. /** @docsNotRequired */
  2066. id: number,
  2067. /** @docsNotRequired */
  2068. url: string,
  2069. /** @docsNotRequired */
  2070. navigationTrigger?: NavigationTrigger,
  2071. /** @docsNotRequired */
  2072. restoredState?: {
  2073. [k: string]: any;
  2074. navigationId: number;
  2075. } | null);
  2076. /** @docsNotRequired */
  2077. toString(): string;
  2078. }
  2079. /**
  2080. * An event triggered when a navigation ends successfully.
  2081. *
  2082. * @see {@link NavigationStart}
  2083. * @see {@link NavigationCancel}
  2084. * @see {@link NavigationError}
  2085. *
  2086. * @publicApi
  2087. */
  2088. declare class NavigationEnd extends RouterEvent {
  2089. /** @docsNotRequired */
  2090. urlAfterRedirects: string;
  2091. readonly type = EventType.NavigationEnd;
  2092. constructor(
  2093. /** @docsNotRequired */
  2094. id: number,
  2095. /** @docsNotRequired */
  2096. url: string,
  2097. /** @docsNotRequired */
  2098. urlAfterRedirects: string);
  2099. /** @docsNotRequired */
  2100. toString(): string;
  2101. }
  2102. /**
  2103. * A code for the `NavigationCancel` event of the `Router` to indicate the
  2104. * reason a navigation failed.
  2105. *
  2106. * @publicApi
  2107. */
  2108. declare enum NavigationCancellationCode {
  2109. /**
  2110. * A navigation failed because a guard returned a `UrlTree` to redirect.
  2111. */
  2112. Redirect = 0,
  2113. /**
  2114. * A navigation failed because a more recent navigation started.
  2115. */
  2116. SupersededByNewNavigation = 1,
  2117. /**
  2118. * A navigation failed because one of the resolvers completed without emitting a value.
  2119. */
  2120. NoDataFromResolver = 2,
  2121. /**
  2122. * A navigation failed because a guard returned `false`.
  2123. */
  2124. GuardRejected = 3
  2125. }
  2126. /**
  2127. * A code for the `NavigationSkipped` event of the `Router` to indicate the
  2128. * reason a navigation was skipped.
  2129. *
  2130. * @publicApi
  2131. */
  2132. declare enum NavigationSkippedCode {
  2133. /**
  2134. * A navigation was skipped because the navigation URL was the same as the current Router URL.
  2135. */
  2136. IgnoredSameUrlNavigation = 0,
  2137. /**
  2138. * A navigation was skipped because the configured `UrlHandlingStrategy` return `false` for both
  2139. * the current Router URL and the target of the navigation.
  2140. *
  2141. * @see {@link UrlHandlingStrategy}
  2142. */
  2143. IgnoredByUrlHandlingStrategy = 1
  2144. }
  2145. /**
  2146. * An event triggered when a navigation is canceled, directly or indirectly.
  2147. * This can happen for several reasons including when a route guard
  2148. * returns `false` or initiates a redirect by returning a `UrlTree`.
  2149. *
  2150. * @see {@link NavigationStart}
  2151. * @see {@link NavigationEnd}
  2152. * @see {@link NavigationError}
  2153. *
  2154. * @publicApi
  2155. */
  2156. declare class NavigationCancel extends RouterEvent {
  2157. /**
  2158. * A description of why the navigation was cancelled. For debug purposes only. Use `code`
  2159. * instead for a stable cancellation reason that can be used in production.
  2160. */
  2161. reason: string;
  2162. /**
  2163. * A code to indicate why the navigation was canceled. This cancellation code is stable for
  2164. * the reason and can be relied on whereas the `reason` string could change and should not be
  2165. * used in production.
  2166. */
  2167. readonly code?: NavigationCancellationCode | undefined;
  2168. readonly type = EventType.NavigationCancel;
  2169. constructor(
  2170. /** @docsNotRequired */
  2171. id: number,
  2172. /** @docsNotRequired */
  2173. url: string,
  2174. /**
  2175. * A description of why the navigation was cancelled. For debug purposes only. Use `code`
  2176. * instead for a stable cancellation reason that can be used in production.
  2177. */
  2178. reason: string,
  2179. /**
  2180. * A code to indicate why the navigation was canceled. This cancellation code is stable for
  2181. * the reason and can be relied on whereas the `reason` string could change and should not be
  2182. * used in production.
  2183. */
  2184. code?: NavigationCancellationCode | undefined);
  2185. /** @docsNotRequired */
  2186. toString(): string;
  2187. }
  2188. /**
  2189. * An event triggered when a navigation is skipped.
  2190. * This can happen for a couple reasons including onSameUrlHandling
  2191. * is set to `ignore` and the navigation URL is not different than the
  2192. * current state.
  2193. *
  2194. * @publicApi
  2195. */
  2196. declare class NavigationSkipped extends RouterEvent {
  2197. /**
  2198. * A description of why the navigation was skipped. For debug purposes only. Use `code`
  2199. * instead for a stable skipped reason that can be used in production.
  2200. */
  2201. reason: string;
  2202. /**
  2203. * A code to indicate why the navigation was skipped. This code is stable for
  2204. * the reason and can be relied on whereas the `reason` string could change and should not be
  2205. * used in production.
  2206. */
  2207. readonly code?: NavigationSkippedCode | undefined;
  2208. readonly type = EventType.NavigationSkipped;
  2209. constructor(
  2210. /** @docsNotRequired */
  2211. id: number,
  2212. /** @docsNotRequired */
  2213. url: string,
  2214. /**
  2215. * A description of why the navigation was skipped. For debug purposes only. Use `code`
  2216. * instead for a stable skipped reason that can be used in production.
  2217. */
  2218. reason: string,
  2219. /**
  2220. * A code to indicate why the navigation was skipped. This code is stable for
  2221. * the reason and can be relied on whereas the `reason` string could change and should not be
  2222. * used in production.
  2223. */
  2224. code?: NavigationSkippedCode | undefined);
  2225. }
  2226. /**
  2227. * An event triggered when a navigation fails due to an unexpected error.
  2228. *
  2229. * @see {@link NavigationStart}
  2230. * @see {@link NavigationEnd}
  2231. * @see {@link NavigationCancel}
  2232. *
  2233. * @publicApi
  2234. */
  2235. declare class NavigationError extends RouterEvent {
  2236. /** @docsNotRequired */
  2237. error: any;
  2238. /**
  2239. * The target of the navigation when the error occurred.
  2240. *
  2241. * Note that this can be `undefined` because an error could have occurred before the
  2242. * `RouterStateSnapshot` was created for the navigation.
  2243. */
  2244. readonly target?: RouterStateSnapshot | undefined;
  2245. readonly type = EventType.NavigationError;
  2246. constructor(
  2247. /** @docsNotRequired */
  2248. id: number,
  2249. /** @docsNotRequired */
  2250. url: string,
  2251. /** @docsNotRequired */
  2252. error: any,
  2253. /**
  2254. * The target of the navigation when the error occurred.
  2255. *
  2256. * Note that this can be `undefined` because an error could have occurred before the
  2257. * `RouterStateSnapshot` was created for the navigation.
  2258. */
  2259. target?: RouterStateSnapshot | undefined);
  2260. /** @docsNotRequired */
  2261. toString(): string;
  2262. }
  2263. /**
  2264. * An event triggered when routes are recognized.
  2265. *
  2266. * @publicApi
  2267. */
  2268. declare class RoutesRecognized extends RouterEvent {
  2269. /** @docsNotRequired */
  2270. urlAfterRedirects: string;
  2271. /** @docsNotRequired */
  2272. state: RouterStateSnapshot;
  2273. readonly type = EventType.RoutesRecognized;
  2274. constructor(
  2275. /** @docsNotRequired */
  2276. id: number,
  2277. /** @docsNotRequired */
  2278. url: string,
  2279. /** @docsNotRequired */
  2280. urlAfterRedirects: string,
  2281. /** @docsNotRequired */
  2282. state: RouterStateSnapshot);
  2283. /** @docsNotRequired */
  2284. toString(): string;
  2285. }
  2286. /**
  2287. * An event triggered at the start of the Guard phase of routing.
  2288. *
  2289. * @see {@link GuardsCheckEnd}
  2290. *
  2291. * @publicApi
  2292. */
  2293. declare class GuardsCheckStart extends RouterEvent {
  2294. /** @docsNotRequired */
  2295. urlAfterRedirects: string;
  2296. /** @docsNotRequired */
  2297. state: RouterStateSnapshot;
  2298. readonly type = EventType.GuardsCheckStart;
  2299. constructor(
  2300. /** @docsNotRequired */
  2301. id: number,
  2302. /** @docsNotRequired */
  2303. url: string,
  2304. /** @docsNotRequired */
  2305. urlAfterRedirects: string,
  2306. /** @docsNotRequired */
  2307. state: RouterStateSnapshot);
  2308. toString(): string;
  2309. }
  2310. /**
  2311. * An event triggered at the end of the Guard phase of routing.
  2312. *
  2313. * @see {@link GuardsCheckStart}
  2314. *
  2315. * @publicApi
  2316. */
  2317. declare class GuardsCheckEnd extends RouterEvent {
  2318. /** @docsNotRequired */
  2319. urlAfterRedirects: string;
  2320. /** @docsNotRequired */
  2321. state: RouterStateSnapshot;
  2322. /** @docsNotRequired */
  2323. shouldActivate: boolean;
  2324. readonly type = EventType.GuardsCheckEnd;
  2325. constructor(
  2326. /** @docsNotRequired */
  2327. id: number,
  2328. /** @docsNotRequired */
  2329. url: string,
  2330. /** @docsNotRequired */
  2331. urlAfterRedirects: string,
  2332. /** @docsNotRequired */
  2333. state: RouterStateSnapshot,
  2334. /** @docsNotRequired */
  2335. shouldActivate: boolean);
  2336. toString(): string;
  2337. }
  2338. /**
  2339. * An event triggered at the start of the Resolve phase of routing.
  2340. *
  2341. * Runs in the "resolve" phase whether or not there is anything to resolve.
  2342. * In future, may change to only run when there are things to be resolved.
  2343. *
  2344. * @see {@link ResolveEnd}
  2345. *
  2346. * @publicApi
  2347. */
  2348. declare class ResolveStart extends RouterEvent {
  2349. /** @docsNotRequired */
  2350. urlAfterRedirects: string;
  2351. /** @docsNotRequired */
  2352. state: RouterStateSnapshot;
  2353. readonly type = EventType.ResolveStart;
  2354. constructor(
  2355. /** @docsNotRequired */
  2356. id: number,
  2357. /** @docsNotRequired */
  2358. url: string,
  2359. /** @docsNotRequired */
  2360. urlAfterRedirects: string,
  2361. /** @docsNotRequired */
  2362. state: RouterStateSnapshot);
  2363. toString(): string;
  2364. }
  2365. /**
  2366. * An event triggered at the end of the Resolve phase of routing.
  2367. * @see {@link ResolveStart}
  2368. *
  2369. * @publicApi
  2370. */
  2371. declare class ResolveEnd extends RouterEvent {
  2372. /** @docsNotRequired */
  2373. urlAfterRedirects: string;
  2374. /** @docsNotRequired */
  2375. state: RouterStateSnapshot;
  2376. readonly type = EventType.ResolveEnd;
  2377. constructor(
  2378. /** @docsNotRequired */
  2379. id: number,
  2380. /** @docsNotRequired */
  2381. url: string,
  2382. /** @docsNotRequired */
  2383. urlAfterRedirects: string,
  2384. /** @docsNotRequired */
  2385. state: RouterStateSnapshot);
  2386. toString(): string;
  2387. }
  2388. /**
  2389. * An event triggered before lazy loading a route configuration.
  2390. *
  2391. * @see {@link RouteConfigLoadEnd}
  2392. *
  2393. * @publicApi
  2394. */
  2395. declare class RouteConfigLoadStart {
  2396. /** @docsNotRequired */
  2397. route: Route;
  2398. readonly type = EventType.RouteConfigLoadStart;
  2399. constructor(
  2400. /** @docsNotRequired */
  2401. route: Route);
  2402. toString(): string;
  2403. }
  2404. /**
  2405. * An event triggered when a route has been lazy loaded.
  2406. *
  2407. * @see {@link RouteConfigLoadStart}
  2408. *
  2409. * @publicApi
  2410. */
  2411. declare class RouteConfigLoadEnd {
  2412. /** @docsNotRequired */
  2413. route: Route;
  2414. readonly type = EventType.RouteConfigLoadEnd;
  2415. constructor(
  2416. /** @docsNotRequired */
  2417. route: Route);
  2418. toString(): string;
  2419. }
  2420. /**
  2421. * An event triggered at the start of the child-activation
  2422. * part of the Resolve phase of routing.
  2423. * @see {@link ChildActivationEnd}
  2424. * @see {@link ResolveStart}
  2425. *
  2426. * @publicApi
  2427. */
  2428. declare class ChildActivationStart {
  2429. /** @docsNotRequired */
  2430. snapshot: ActivatedRouteSnapshot;
  2431. readonly type = EventType.ChildActivationStart;
  2432. constructor(
  2433. /** @docsNotRequired */
  2434. snapshot: ActivatedRouteSnapshot);
  2435. toString(): string;
  2436. }
  2437. /**
  2438. * An event triggered at the end of the child-activation part
  2439. * of the Resolve phase of routing.
  2440. * @see {@link ChildActivationStart}
  2441. * @see {@link ResolveStart}
  2442. * @publicApi
  2443. */
  2444. declare class ChildActivationEnd {
  2445. /** @docsNotRequired */
  2446. snapshot: ActivatedRouteSnapshot;
  2447. readonly type = EventType.ChildActivationEnd;
  2448. constructor(
  2449. /** @docsNotRequired */
  2450. snapshot: ActivatedRouteSnapshot);
  2451. toString(): string;
  2452. }
  2453. /**
  2454. * An event triggered at the start of the activation part
  2455. * of the Resolve phase of routing.
  2456. * @see {@link ActivationEnd}
  2457. * @see {@link ResolveStart}
  2458. *
  2459. * @publicApi
  2460. */
  2461. declare class ActivationStart {
  2462. /** @docsNotRequired */
  2463. snapshot: ActivatedRouteSnapshot;
  2464. readonly type = EventType.ActivationStart;
  2465. constructor(
  2466. /** @docsNotRequired */
  2467. snapshot: ActivatedRouteSnapshot);
  2468. toString(): string;
  2469. }
  2470. /**
  2471. * An event triggered at the end of the activation part
  2472. * of the Resolve phase of routing.
  2473. * @see {@link ActivationStart}
  2474. * @see {@link ResolveStart}
  2475. *
  2476. * @publicApi
  2477. */
  2478. declare class ActivationEnd {
  2479. /** @docsNotRequired */
  2480. snapshot: ActivatedRouteSnapshot;
  2481. readonly type = EventType.ActivationEnd;
  2482. constructor(
  2483. /** @docsNotRequired */
  2484. snapshot: ActivatedRouteSnapshot);
  2485. toString(): string;
  2486. }
  2487. /**
  2488. * An event triggered by scrolling.
  2489. *
  2490. * @publicApi
  2491. */
  2492. declare class Scroll {
  2493. /** @docsNotRequired */
  2494. readonly routerEvent: NavigationEnd | NavigationSkipped;
  2495. /** @docsNotRequired */
  2496. readonly position: [number, number] | null;
  2497. /** @docsNotRequired */
  2498. readonly anchor: string | null;
  2499. readonly type = EventType.Scroll;
  2500. constructor(
  2501. /** @docsNotRequired */
  2502. routerEvent: NavigationEnd | NavigationSkipped,
  2503. /** @docsNotRequired */
  2504. position: [number, number] | null,
  2505. /** @docsNotRequired */
  2506. anchor: string | null);
  2507. toString(): string;
  2508. }
  2509. /**
  2510. * Router events that allow you to track the lifecycle of the router.
  2511. *
  2512. * The events occur in the following sequence:
  2513. *
  2514. * * [NavigationStart](api/router/NavigationStart): Navigation starts.
  2515. * * [RouteConfigLoadStart](api/router/RouteConfigLoadStart): Before
  2516. * the router [lazy loads](guide/routing/common-router-tasks#lazy-loading) a route configuration.
  2517. * * [RouteConfigLoadEnd](api/router/RouteConfigLoadEnd): After a route has been lazy loaded.
  2518. * * [RoutesRecognized](api/router/RoutesRecognized): When the router parses the URL
  2519. * and the routes are recognized.
  2520. * * [GuardsCheckStart](api/router/GuardsCheckStart): When the router begins the *guards*
  2521. * phase of routing.
  2522. * * [ChildActivationStart](api/router/ChildActivationStart): When the router
  2523. * begins activating a route's children.
  2524. * * [ActivationStart](api/router/ActivationStart): When the router begins activating a route.
  2525. * * [GuardsCheckEnd](api/router/GuardsCheckEnd): When the router finishes the *guards*
  2526. * phase of routing successfully.
  2527. * * [ResolveStart](api/router/ResolveStart): When the router begins the *resolve*
  2528. * phase of routing.
  2529. * * [ResolveEnd](api/router/ResolveEnd): When the router finishes the *resolve*
  2530. * phase of routing successfully.
  2531. * * [ChildActivationEnd](api/router/ChildActivationEnd): When the router finishes
  2532. * activating a route's children.
  2533. * * [ActivationEnd](api/router/ActivationEnd): When the router finishes activating a route.
  2534. * * [NavigationEnd](api/router/NavigationEnd): When navigation ends successfully.
  2535. * * [NavigationCancel](api/router/NavigationCancel): When navigation is canceled.
  2536. * * [NavigationError](api/router/NavigationError): When navigation fails
  2537. * due to an unexpected error.
  2538. * * [Scroll](api/router/Scroll): When the user scrolls.
  2539. *
  2540. * @publicApi
  2541. */
  2542. type Event = NavigationStart | NavigationEnd | NavigationCancel | NavigationError | RoutesRecognized | GuardsCheckStart | GuardsCheckEnd | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivationStart | ChildActivationEnd | ActivationStart | ActivationEnd | Scroll | ResolveStart | ResolveEnd | NavigationSkipped;
  2543. /**
  2544. * @description
  2545. *
  2546. * Represents the detached route tree.
  2547. *
  2548. * This is an opaque value the router will give to a custom route reuse strategy
  2549. * to store and retrieve later on.
  2550. *
  2551. * @publicApi
  2552. */
  2553. type DetachedRouteHandle = {};
  2554. /**
  2555. * @description
  2556. *
  2557. * Provides a way to customize when activated routes get reused.
  2558. *
  2559. * @publicApi
  2560. */
  2561. declare abstract class RouteReuseStrategy {
  2562. /** Determines if this route (and its subtree) should be detached to be reused later */
  2563. abstract shouldDetach(route: ActivatedRouteSnapshot): boolean;
  2564. /**
  2565. * Stores the detached route.
  2566. *
  2567. * Storing a `null` value should erase the previously stored value.
  2568. */
  2569. abstract store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void;
  2570. /** Determines if this route (and its subtree) should be reattached */
  2571. abstract shouldAttach(route: ActivatedRouteSnapshot): boolean;
  2572. /** Retrieves the previously stored route */
  2573. abstract retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null;
  2574. /** Determines if a route should be reused */
  2575. abstract shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
  2576. static ɵfac: i0.ɵɵFactoryDeclaration<RouteReuseStrategy, never>;
  2577. static ɵprov: i0.ɵɵInjectableDeclaration<RouteReuseStrategy>;
  2578. }
  2579. /**
  2580. * @description
  2581. *
  2582. * This base route reuse strategy only reuses routes when the matched router configs are
  2583. * identical. This prevents components from being destroyed and recreated
  2584. * when just the route parameters, query parameters or fragment change
  2585. * (that is, the existing component is _reused_).
  2586. *
  2587. * This strategy does not store any routes for later reuse.
  2588. *
  2589. * Angular uses this strategy by default.
  2590. *
  2591. *
  2592. * It can be used as a base class for custom route reuse strategies, i.e. you can create your own
  2593. * class that extends the `BaseRouteReuseStrategy` one.
  2594. * @publicApi
  2595. */
  2596. declare abstract class BaseRouteReuseStrategy implements RouteReuseStrategy {
  2597. /**
  2598. * Whether the given route should detach for later reuse.
  2599. * Always returns false for `BaseRouteReuseStrategy`.
  2600. * */
  2601. shouldDetach(route: ActivatedRouteSnapshot): boolean;
  2602. /**
  2603. * A no-op; the route is never stored since this strategy never detaches routes for later re-use.
  2604. */
  2605. store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void;
  2606. /** Returns `false`, meaning the route (and its subtree) is never reattached */
  2607. shouldAttach(route: ActivatedRouteSnapshot): boolean;
  2608. /** Returns `null` because this strategy does not store routes for later re-use. */
  2609. retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null;
  2610. /**
  2611. * Determines if a route should be reused.
  2612. * This strategy returns `true` when the future route config and current route config are
  2613. * identical.
  2614. */
  2615. shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean;
  2616. }
  2617. /**
  2618. * An `InjectionToken` provided by the `RouterOutlet` and can be set using the `routerOutletData`
  2619. * input.
  2620. *
  2621. * When unset, this value is `null` by default.
  2622. *
  2623. * @usageNotes
  2624. *
  2625. * To set the data from the template of the component with `router-outlet`:
  2626. * ```html
  2627. * <router-outlet [routerOutletData]="{name: 'Angular'}" />
  2628. * ```
  2629. *
  2630. * To read the data in the routed component:
  2631. * ```ts
  2632. * data = inject(ROUTER_OUTLET_DATA) as Signal<{name: string}>;
  2633. * ```
  2634. *
  2635. * @publicApi
  2636. */
  2637. declare const ROUTER_OUTLET_DATA: InjectionToken<Signal<unknown>>;
  2638. /**
  2639. * An interface that defines the contract for developing a component outlet for the `Router`.
  2640. *
  2641. * An outlet acts as a placeholder that Angular dynamically fills based on the current router state.
  2642. *
  2643. * A router outlet should register itself with the `Router` via
  2644. * `ChildrenOutletContexts#onChildOutletCreated` and unregister with
  2645. * `ChildrenOutletContexts#onChildOutletDestroyed`. When the `Router` identifies a matched `Route`,
  2646. * it looks for a registered outlet in the `ChildrenOutletContexts` and activates it.
  2647. *
  2648. * @see {@link ChildrenOutletContexts}
  2649. * @publicApi
  2650. */
  2651. interface RouterOutletContract {
  2652. /**
  2653. * Whether the given outlet is activated.
  2654. *
  2655. * An outlet is considered "activated" if it has an active component.
  2656. */
  2657. isActivated: boolean;
  2658. /** The instance of the activated component or `null` if the outlet is not activated. */
  2659. component: Object | null;
  2660. /**
  2661. * The `Data` of the `ActivatedRoute` snapshot.
  2662. */
  2663. activatedRouteData: Data;
  2664. /**
  2665. * The `ActivatedRoute` for the outlet or `null` if the outlet is not activated.
  2666. */
  2667. activatedRoute: ActivatedRoute | null;
  2668. /**
  2669. * Called by the `Router` when the outlet should activate (create a component).
  2670. */
  2671. activateWith(activatedRoute: ActivatedRoute, environmentInjector: EnvironmentInjector): void;
  2672. /**
  2673. * A request to destroy the currently activated component.
  2674. *
  2675. * When a `RouteReuseStrategy` indicates that an `ActivatedRoute` should be removed but stored for
  2676. * later re-use rather than destroyed, the `Router` will call `detach` instead.
  2677. */
  2678. deactivate(): void;
  2679. /**
  2680. * Called when the `RouteReuseStrategy` instructs to detach the subtree.
  2681. *
  2682. * This is similar to `deactivate`, but the activated component should _not_ be destroyed.
  2683. * Instead, it is returned so that it can be reattached later via the `attach` method.
  2684. */
  2685. detach(): ComponentRef<unknown>;
  2686. /**
  2687. * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree.
  2688. */
  2689. attach(ref: ComponentRef<unknown>, activatedRoute: ActivatedRoute): void;
  2690. /**
  2691. * Emits an activate event when a new component is instantiated
  2692. **/
  2693. activateEvents?: EventEmitter<unknown>;
  2694. /**
  2695. * Emits a deactivate event when a component is destroyed.
  2696. */
  2697. deactivateEvents?: EventEmitter<unknown>;
  2698. /**
  2699. * Emits an attached component instance when the `RouteReuseStrategy` instructs to re-attach a
  2700. * previously detached subtree.
  2701. **/
  2702. attachEvents?: EventEmitter<unknown>;
  2703. /**
  2704. * Emits a detached component instance when the `RouteReuseStrategy` instructs to detach the
  2705. * subtree.
  2706. */
  2707. detachEvents?: EventEmitter<unknown>;
  2708. /**
  2709. * Used to indicate that the outlet is able to bind data from the `Router` to the outlet
  2710. * component's inputs.
  2711. *
  2712. * When this is `undefined` or `false` and the developer has opted in to the
  2713. * feature using `withComponentInputBinding`, a warning will be logged in dev mode if this outlet
  2714. * is used in the application.
  2715. */
  2716. readonly supportsBindingToComponentInputs?: true;
  2717. }
  2718. /**
  2719. * @description
  2720. *
  2721. * Acts as a placeholder that Angular dynamically fills based on the current router state.
  2722. *
  2723. * Each outlet can have a unique name, determined by the optional `name` attribute.
  2724. * The name cannot be set or changed dynamically. If not set, default value is "primary".
  2725. *
  2726. * ```html
  2727. * <router-outlet></router-outlet>
  2728. * <router-outlet name='left'></router-outlet>
  2729. * <router-outlet name='right'></router-outlet>
  2730. * ```
  2731. *
  2732. * Named outlets can be the targets of secondary routes.
  2733. * The `Route` object for a secondary route has an `outlet` property to identify the target outlet:
  2734. *
  2735. * `{path: <base-path>, component: <component>, outlet: <target_outlet_name>}`
  2736. *
  2737. * Using named outlets and secondary routes, you can target multiple outlets in
  2738. * the same `RouterLink` directive.
  2739. *
  2740. * The router keeps track of separate branches in a navigation tree for each named outlet and
  2741. * generates a representation of that tree in the URL.
  2742. * The URL for a secondary route uses the following syntax to specify both the primary and secondary
  2743. * routes at the same time:
  2744. *
  2745. * `http://base-path/primary-route-path(outlet-name:route-path)`
  2746. *
  2747. * A router outlet emits an activate event when a new component is instantiated,
  2748. * deactivate event when a component is destroyed.
  2749. * An attached event emits when the `RouteReuseStrategy` instructs the outlet to reattach the
  2750. * subtree, and the detached event emits when the `RouteReuseStrategy` instructs the outlet to
  2751. * detach the subtree.
  2752. *
  2753. * ```html
  2754. * <router-outlet
  2755. * (activate)='onActivate($event)'
  2756. * (deactivate)='onDeactivate($event)'
  2757. * (attach)='onAttach($event)'
  2758. * (detach)='onDetach($event)'></router-outlet>
  2759. * ```
  2760. *
  2761. * @see {@link RouterLink}
  2762. * @see {@link Route}
  2763. * @ngModule RouterModule
  2764. *
  2765. * @publicApi
  2766. */
  2767. declare class RouterOutlet implements OnDestroy, OnInit, RouterOutletContract {
  2768. private activated;
  2769. private _activatedRoute;
  2770. /**
  2771. * The name of the outlet
  2772. *
  2773. */
  2774. name: string;
  2775. activateEvents: EventEmitter<any>;
  2776. deactivateEvents: EventEmitter<any>;
  2777. /**
  2778. * Emits an attached component instance when the `RouteReuseStrategy` instructs to re-attach a
  2779. * previously detached subtree.
  2780. **/
  2781. attachEvents: EventEmitter<unknown>;
  2782. /**
  2783. * Emits a detached component instance when the `RouteReuseStrategy` instructs to detach the
  2784. * subtree.
  2785. */
  2786. detachEvents: EventEmitter<unknown>;
  2787. /**
  2788. * Data that will be provided to the child injector through the `ROUTER_OUTLET_DATA` token.
  2789. *
  2790. * When unset, the value of the token is `undefined` by default.
  2791. */
  2792. readonly routerOutletData: i0.InputSignal<unknown>;
  2793. private parentContexts;
  2794. private location;
  2795. private changeDetector;
  2796. private inputBinder;
  2797. /** @nodoc */
  2798. readonly supportsBindingToComponentInputs = true;
  2799. /** @nodoc */
  2800. ngOnChanges(changes: SimpleChanges): void;
  2801. /** @nodoc */
  2802. ngOnDestroy(): void;
  2803. private isTrackedInParentContexts;
  2804. /** @nodoc */
  2805. ngOnInit(): void;
  2806. private initializeOutletWithName;
  2807. get isActivated(): boolean;
  2808. /**
  2809. * @returns The currently activated component instance.
  2810. * @throws An error if the outlet is not activated.
  2811. */
  2812. get component(): Object;
  2813. get activatedRoute(): ActivatedRoute;
  2814. get activatedRouteData(): Data;
  2815. /**
  2816. * Called when the `RouteReuseStrategy` instructs to detach the subtree
  2817. */
  2818. detach(): ComponentRef<any>;
  2819. /**
  2820. * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree
  2821. */
  2822. attach(ref: ComponentRef<any>, activatedRoute: ActivatedRoute): void;
  2823. deactivate(): void;
  2824. activateWith(activatedRoute: ActivatedRoute, environmentInjector: EnvironmentInjector): void;
  2825. static ɵfac: i0.ɵɵFactoryDeclaration<RouterOutlet, never>;
  2826. static ɵdir: i0.ɵɵDirectiveDeclaration<RouterOutlet, "router-outlet", ["outlet"], { "name": { "alias": "name"; "required": false; }; "routerOutletData": { "alias": "routerOutletData"; "required": false; "isSignal": true; }; }, { "activateEvents": "activate"; "deactivateEvents": "deactivate"; "attachEvents": "attach"; "detachEvents": "detach"; }, never, never, true, never>;
  2827. }
  2828. /**
  2829. * Store contextual information about a `RouterOutlet`
  2830. *
  2831. * @publicApi
  2832. */
  2833. declare class OutletContext {
  2834. private readonly rootInjector;
  2835. outlet: RouterOutletContract | null;
  2836. route: ActivatedRoute | null;
  2837. children: ChildrenOutletContexts;
  2838. attachRef: ComponentRef<any> | null;
  2839. get injector(): EnvironmentInjector;
  2840. constructor(rootInjector: EnvironmentInjector);
  2841. }
  2842. /**
  2843. * Store contextual information about the children (= nested) `RouterOutlet`
  2844. *
  2845. * @publicApi
  2846. */
  2847. declare class ChildrenOutletContexts {
  2848. private rootInjector;
  2849. private contexts;
  2850. /** @nodoc */
  2851. constructor(rootInjector: EnvironmentInjector);
  2852. /** Called when a `RouterOutlet` directive is instantiated */
  2853. onChildOutletCreated(childName: string, outlet: RouterOutletContract): void;
  2854. /**
  2855. * Called when a `RouterOutlet` directive is destroyed.
  2856. * We need to keep the context as the outlet could be destroyed inside a NgIf and might be
  2857. * re-created later.
  2858. */
  2859. onChildOutletDestroyed(childName: string): void;
  2860. /**
  2861. * Called when the corresponding route is deactivated during navigation.
  2862. * Because the component get destroyed, all children outlet are destroyed.
  2863. */
  2864. onOutletDeactivated(): Map<string, OutletContext>;
  2865. onOutletReAttached(contexts: Map<string, OutletContext>): void;
  2866. getOrCreateContext(childName: string): OutletContext;
  2867. getContext(childName: string): OutletContext | null;
  2868. static ɵfac: i0.ɵɵFactoryDeclaration<ChildrenOutletContexts, never>;
  2869. static ɵprov: i0.ɵɵInjectableDeclaration<ChildrenOutletContexts>;
  2870. }
  2871. /**
  2872. * @description
  2873. *
  2874. * Options that modify the `Router` URL.
  2875. * Supply an object containing any of these properties to a `Router` navigation function to
  2876. * control how the target URL should be constructed.
  2877. *
  2878. * @see {@link Router#navigate}
  2879. * @see {@link Router#createUrlTree}
  2880. * @see [Routing and Navigation guide](guide/routing/common-router-tasks)
  2881. *
  2882. * @publicApi
  2883. */
  2884. interface UrlCreationOptions {
  2885. /**
  2886. * Specifies a root URI to use for relative navigation.
  2887. *
  2888. * For example, consider the following route configuration where the parent route
  2889. * has two children.
  2890. *
  2891. * ```
  2892. * [{
  2893. * path: 'parent',
  2894. * component: ParentComponent,
  2895. * children: [{
  2896. * path: 'list',
  2897. * component: ListComponent
  2898. * },{
  2899. * path: 'child',
  2900. * component: ChildComponent
  2901. * }]
  2902. * }]
  2903. * ```
  2904. *
  2905. * The following `go()` function navigates to the `list` route by
  2906. * interpreting the destination URI as relative to the activated `child` route
  2907. *
  2908. * ```ts
  2909. * @Component({...})
  2910. * class ChildComponent {
  2911. * constructor(private router: Router, private route: ActivatedRoute) {}
  2912. *
  2913. * go() {
  2914. * router.navigate(['../list'], { relativeTo: this.route });
  2915. * }
  2916. * }
  2917. * ```
  2918. *
  2919. * A value of `null` or `undefined` indicates that the navigation commands should be applied
  2920. * relative to the root.
  2921. */
  2922. relativeTo?: ActivatedRoute | null;
  2923. /**
  2924. * Sets query parameters to the URL.
  2925. *
  2926. * ```
  2927. * // Navigate to /results?page=1
  2928. * router.navigate(['/results'], { queryParams: { page: 1 } });
  2929. * ```
  2930. */
  2931. queryParams?: Params | null;
  2932. /**
  2933. * Sets the hash fragment for the URL.
  2934. *
  2935. * ```
  2936. * // Navigate to /results#top
  2937. * router.navigate(['/results'], { fragment: 'top' });
  2938. * ```
  2939. */
  2940. fragment?: string;
  2941. /**
  2942. * How to handle query parameters in the router link for the next navigation.
  2943. * One of:
  2944. * * `preserve` : Preserve current parameters.
  2945. * * `merge` : Merge new with current parameters.
  2946. *
  2947. * The "preserve" option discards any new query params:
  2948. * ```
  2949. * // from /view1?page=1 to/view2?page=1
  2950. * router.navigate(['/view2'], { queryParams: { page: 2 }, queryParamsHandling: "preserve"
  2951. * });
  2952. * ```
  2953. * The "merge" option appends new query params to the params from the current URL:
  2954. * ```
  2955. * // from /view1?page=1 to/view2?page=1&otherKey=2
  2956. * router.navigate(['/view2'], { queryParams: { otherKey: 2 }, queryParamsHandling: "merge"
  2957. * });
  2958. * ```
  2959. * In case of a key collision between current parameters and those in the `queryParams` object,
  2960. * the new value is used.
  2961. *
  2962. */
  2963. queryParamsHandling?: QueryParamsHandling | null;
  2964. /**
  2965. * When true, preserves the URL fragment for the next navigation
  2966. *
  2967. * ```
  2968. * // Preserve fragment from /results#top to /view#top
  2969. * router.navigate(['/view'], { preserveFragment: true });
  2970. * ```
  2971. */
  2972. preserveFragment?: boolean;
  2973. }
  2974. /**
  2975. * @description
  2976. *
  2977. * Options that modify the `Router` navigation strategy.
  2978. * Supply an object containing any of these properties to a `Router` navigation function to
  2979. * control how the target URL should be constructed or interpreted.
  2980. *
  2981. * @see {@link Router#navigate}
  2982. * @see {@link Router#navigateByUrl}
  2983. * @see {@link Router#createurltree}
  2984. * @see [Routing and Navigation guide](guide/routing/common-router-tasks)
  2985. * @see {@link UrlCreationOptions}
  2986. * @see {@link NavigationBehaviorOptions}
  2987. *
  2988. * @publicApi
  2989. */
  2990. interface NavigationExtras extends UrlCreationOptions, NavigationBehaviorOptions {
  2991. }
  2992. type RestoredState = {
  2993. [k: string]: any;
  2994. navigationId: number;
  2995. ɵrouterPageId?: number;
  2996. };
  2997. /**
  2998. * Information about a navigation operation.
  2999. * Retrieve the most recent navigation object with the
  3000. * [Router.getCurrentNavigation() method](api/router/Router#getcurrentnavigation) .
  3001. *
  3002. * * *id* : The unique identifier of the current navigation.
  3003. * * *initialUrl* : The target URL passed into the `Router#navigateByUrl()` call before navigation.
  3004. * This is the value before the router has parsed or applied redirects to it.
  3005. * * *extractedUrl* : The initial target URL after being parsed with `UrlSerializer.extract()`.
  3006. * * *finalUrl* : The extracted URL after redirects have been applied.
  3007. * This URL may not be available immediately, therefore this property can be `undefined`.
  3008. * It is guaranteed to be set after the `RoutesRecognized` event fires.
  3009. * * *trigger* : Identifies how this navigation was triggered.
  3010. * -- 'imperative'--Triggered by `router.navigateByUrl` or `router.navigate`.
  3011. * -- 'popstate'--Triggered by a popstate event.
  3012. * -- 'hashchange'--Triggered by a hashchange event.
  3013. * * *extras* : A `NavigationExtras` options object that controlled the strategy used for this
  3014. * navigation.
  3015. * * *previousNavigation* : The previously successful `Navigation` object. Only one previous
  3016. * navigation is available, therefore this previous `Navigation` object has a `null` value for its
  3017. * own `previousNavigation`.
  3018. *
  3019. * @publicApi
  3020. */
  3021. interface Navigation {
  3022. /**
  3023. * The unique identifier of the current navigation.
  3024. */
  3025. id: number;
  3026. /**
  3027. * The target URL passed into the `Router#navigateByUrl()` call before navigation. This is
  3028. * the value before the router has parsed or applied redirects to it.
  3029. */
  3030. initialUrl: UrlTree;
  3031. /**
  3032. * The initial target URL after being parsed with `UrlHandlingStrategy.extract()`.
  3033. */
  3034. extractedUrl: UrlTree;
  3035. /**
  3036. * The extracted URL after redirects have been applied.
  3037. * This URL may not be available immediately, therefore this property can be `undefined`.
  3038. * It is guaranteed to be set after the `RoutesRecognized` event fires.
  3039. */
  3040. finalUrl?: UrlTree;
  3041. /**
  3042. * Identifies how this navigation was triggered.
  3043. *
  3044. * * 'imperative'--Triggered by `router.navigateByUrl` or `router.navigate`.
  3045. * * 'popstate'--Triggered by a popstate event.
  3046. * * 'hashchange'--Triggered by a hashchange event.
  3047. */
  3048. trigger: 'imperative' | 'popstate' | 'hashchange';
  3049. /**
  3050. * Options that controlled the strategy used for this navigation.
  3051. * See `NavigationExtras`.
  3052. */
  3053. extras: NavigationExtras;
  3054. /**
  3055. * The previously successful `Navigation` object. Only one previous navigation
  3056. * is available, therefore this previous `Navigation` object has a `null` value
  3057. * for its own `previousNavigation`.
  3058. */
  3059. previousNavigation: Navigation | null;
  3060. }
  3061. /**
  3062. * @description
  3063. *
  3064. * A service that facilitates navigation among views and URL manipulation capabilities.
  3065. * This service is provided in the root scope and configured with [provideRouter](api/router/provideRouter).
  3066. *
  3067. * @see {@link Route}
  3068. * @see {@link provideRouter}
  3069. * @see [Routing and Navigation Guide](guide/routing/common-router-tasks).
  3070. *
  3071. * @ngModule RouterModule
  3072. *
  3073. * @publicApi
  3074. */
  3075. declare class Router {
  3076. private get currentUrlTree();
  3077. private get rawUrlTree();
  3078. private disposed;
  3079. private nonRouterCurrentEntryChangeSubscription?;
  3080. private readonly console;
  3081. private readonly stateManager;
  3082. private readonly options;
  3083. private readonly pendingTasks;
  3084. private readonly urlUpdateStrategy;
  3085. private readonly navigationTransitions;
  3086. private readonly urlSerializer;
  3087. private readonly location;
  3088. private readonly urlHandlingStrategy;
  3089. /**
  3090. * The private `Subject` type for the public events exposed in the getter. This is used internally
  3091. * to push events to. The separate field allows us to expose separate types in the public API
  3092. * (i.e., an Observable rather than the Subject).
  3093. */
  3094. private _events;
  3095. /**
  3096. * An event stream for routing events.
  3097. */
  3098. get events(): Observable<Event>;
  3099. /**
  3100. * The current state of routing in this NgModule.
  3101. */
  3102. get routerState(): _angular_router.RouterState;
  3103. /**
  3104. * True if at least one navigation event has occurred,
  3105. * false otherwise.
  3106. */
  3107. navigated: boolean;
  3108. /**
  3109. * A strategy for re-using routes.
  3110. *
  3111. * @deprecated Configure using `providers` instead:
  3112. * `{provide: RouteReuseStrategy, useClass: MyStrategy}`.
  3113. */
  3114. routeReuseStrategy: RouteReuseStrategy;
  3115. /**
  3116. * How to handle a navigation request to the current URL.
  3117. *
  3118. *
  3119. * @deprecated Configure this through `provideRouter` or `RouterModule.forRoot` instead.
  3120. * @see {@link withRouterConfig}
  3121. * @see {@link provideRouter}
  3122. * @see {@link RouterModule}
  3123. */
  3124. onSameUrlNavigation: OnSameUrlNavigation;
  3125. config: Routes;
  3126. /**
  3127. * Indicates whether the application has opted in to binding Router data to component inputs.
  3128. *
  3129. * This option is enabled by the `withComponentInputBinding` feature of `provideRouter` or
  3130. * `bindToComponentInputs` in the `ExtraOptions` of `RouterModule.forRoot`.
  3131. */
  3132. readonly componentInputBindingEnabled: boolean;
  3133. constructor();
  3134. private eventsSubscription;
  3135. private subscribeToNavigationEvents;
  3136. /**
  3137. * Sets up the location change listener and performs the initial navigation.
  3138. */
  3139. initialNavigation(): void;
  3140. /**
  3141. * Sets up the location change listener. This listener detects navigations triggered from outside
  3142. * the Router (the browser back/forward buttons, for example) and schedules a corresponding Router
  3143. * navigation so that the correct events, guards, etc. are triggered.
  3144. */
  3145. setUpLocationChangeListener(): void;
  3146. /**
  3147. * Schedules a router navigation to synchronize Router state with the browser state.
  3148. *
  3149. * This is done as a response to a popstate event and the initial navigation. These
  3150. * two scenarios represent times when the browser URL/state has been updated and
  3151. * the Router needs to respond to ensure its internal state matches.
  3152. */
  3153. private navigateToSyncWithBrowser;
  3154. /** The current URL. */
  3155. get url(): string;
  3156. /**
  3157. * Returns the current `Navigation` object when the router is navigating,
  3158. * and `null` when idle.
  3159. */
  3160. getCurrentNavigation(): Navigation | null;
  3161. /**
  3162. * The `Navigation` object of the most recent navigation to succeed and `null` if there
  3163. * has not been a successful navigation yet.
  3164. */
  3165. get lastSuccessfulNavigation(): Navigation | null;
  3166. /**
  3167. * Resets the route configuration used for navigation and generating links.
  3168. *
  3169. * @param config The route array for the new configuration.
  3170. *
  3171. * @usageNotes
  3172. *
  3173. * ```ts
  3174. * router.resetConfig([
  3175. * { path: 'team/:id', component: TeamCmp, children: [
  3176. * { path: 'simple', component: SimpleCmp },
  3177. * { path: 'user/:name', component: UserCmp }
  3178. * ]}
  3179. * ]);
  3180. * ```
  3181. */
  3182. resetConfig(config: Routes): void;
  3183. /** @nodoc */
  3184. ngOnDestroy(): void;
  3185. /** Disposes of the router. */
  3186. dispose(): void;
  3187. /**
  3188. * Appends URL segments to the current URL tree to create a new URL tree.
  3189. *
  3190. * @param commands An array of URL fragments with which to construct the new URL tree.
  3191. * If the path is static, can be the literal URL string. For a dynamic path, pass an array of path
  3192. * segments, followed by the parameters for each segment.
  3193. * The fragments are applied to the current URL tree or the one provided in the `relativeTo`
  3194. * property of the options object, if supplied.
  3195. * @param navigationExtras Options that control the navigation strategy.
  3196. * @returns The new URL tree.
  3197. *
  3198. * @usageNotes
  3199. *
  3200. * ```
  3201. * // create /team/33/user/11
  3202. * router.createUrlTree(['/team', 33, 'user', 11]);
  3203. *
  3204. * // create /team/33;expand=true/user/11
  3205. * router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
  3206. *
  3207. * // you can collapse static segments like this (this works only with the first passed-in value):
  3208. * router.createUrlTree(['/team/33/user', userId]);
  3209. *
  3210. * // If the first segment can contain slashes, and you do not want the router to split it,
  3211. * // you can do the following:
  3212. * router.createUrlTree([{segmentPath: '/one/two'}]);
  3213. *
  3214. * // create /team/33/(user/11//right:chat)
  3215. * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: 'chat'}}]);
  3216. *
  3217. * // remove the right secondary node
  3218. * router.createUrlTree(['/team', 33, {outlets: {primary: 'user/11', right: null}}]);
  3219. *
  3220. * // assuming the current url is `/team/33/user/11` and the route points to `user/11`
  3221. *
  3222. * // navigate to /team/33/user/11/details
  3223. * router.createUrlTree(['details'], {relativeTo: route});
  3224. *
  3225. * // navigate to /team/33/user/22
  3226. * router.createUrlTree(['../22'], {relativeTo: route});
  3227. *
  3228. * // navigate to /team/44/user/22
  3229. * router.createUrlTree(['../../team/44/user/22'], {relativeTo: route});
  3230. *
  3231. * Note that a value of `null` or `undefined` for `relativeTo` indicates that the
  3232. * tree should be created relative to the root.
  3233. * ```
  3234. */
  3235. createUrlTree(commands: any[], navigationExtras?: UrlCreationOptions): UrlTree;
  3236. /**
  3237. * Navigates to a view using an absolute route path.
  3238. *
  3239. * @param url An absolute path for a defined route. The function does not apply any delta to the
  3240. * current URL.
  3241. * @param extras An object containing properties that modify the navigation strategy.
  3242. *
  3243. * @returns A Promise that resolves to 'true' when navigation succeeds,
  3244. * to 'false' when navigation fails, or is rejected on error.
  3245. *
  3246. * @usageNotes
  3247. *
  3248. * The following calls request navigation to an absolute path.
  3249. *
  3250. * ```ts
  3251. * router.navigateByUrl("/team/33/user/11");
  3252. *
  3253. * // Navigate without updating the URL
  3254. * router.navigateByUrl("/team/33/user/11", { skipLocationChange: true });
  3255. * ```
  3256. *
  3257. * @see [Routing and Navigation guide](guide/routing/common-router-tasks)
  3258. *
  3259. */
  3260. navigateByUrl(url: string | UrlTree, extras?: NavigationBehaviorOptions): Promise<boolean>;
  3261. /**
  3262. * Navigate based on the provided array of commands and a starting point.
  3263. * If no starting route is provided, the navigation is absolute.
  3264. *
  3265. * @param commands An array of URL fragments with which to construct the target URL.
  3266. * If the path is static, can be the literal URL string. For a dynamic path, pass an array of path
  3267. * segments, followed by the parameters for each segment.
  3268. * The fragments are applied to the current URL or the one provided in the `relativeTo` property
  3269. * of the options object, if supplied.
  3270. * @param extras An options object that determines how the URL should be constructed or
  3271. * interpreted.
  3272. *
  3273. * @returns A Promise that resolves to `true` when navigation succeeds, or `false` when navigation
  3274. * fails. The Promise is rejected when an error occurs if `resolveNavigationPromiseOnError` is
  3275. * not `true`.
  3276. *
  3277. * @usageNotes
  3278. *
  3279. * The following calls request navigation to a dynamic route path relative to the current URL.
  3280. *
  3281. * ```ts
  3282. * router.navigate(['team', 33, 'user', 11], {relativeTo: route});
  3283. *
  3284. * // Navigate without updating the URL, overriding the default behavior
  3285. * router.navigate(['team', 33, 'user', 11], {relativeTo: route, skipLocationChange: true});
  3286. * ```
  3287. *
  3288. * @see [Routing and Navigation guide](guide/routing/common-router-tasks)
  3289. *
  3290. */
  3291. navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
  3292. /** Serializes a `UrlTree` into a string */
  3293. serializeUrl(url: UrlTree): string;
  3294. /** Parses a string into a `UrlTree` */
  3295. parseUrl(url: string): UrlTree;
  3296. /**
  3297. * Returns whether the url is activated.
  3298. *
  3299. * @deprecated
  3300. * Use `IsActiveMatchOptions` instead.
  3301. *
  3302. * - The equivalent `IsActiveMatchOptions` for `true` is
  3303. * `{paths: 'exact', queryParams: 'exact', fragment: 'ignored', matrixParams: 'ignored'}`.
  3304. * - The equivalent for `false` is
  3305. * `{paths: 'subset', queryParams: 'subset', fragment: 'ignored', matrixParams: 'ignored'}`.
  3306. */
  3307. isActive(url: string | UrlTree, exact: boolean): boolean;
  3308. /**
  3309. * Returns whether the url is activated.
  3310. */
  3311. isActive(url: string | UrlTree, matchOptions: IsActiveMatchOptions): boolean;
  3312. private removeEmptyProps;
  3313. private scheduleNavigation;
  3314. static ɵfac: i0.ɵɵFactoryDeclaration<Router, never>;
  3315. static ɵprov: i0.ɵɵInjectableDeclaration<Router>;
  3316. }
  3317. /**
  3318. * @description
  3319. *
  3320. * When applied to an element in a template, makes that element a link
  3321. * that initiates navigation to a route. Navigation opens one or more routed components
  3322. * in one or more `<router-outlet>` locations on the page.
  3323. *
  3324. * Given a route configuration `[{ path: 'user/:name', component: UserCmp }]`,
  3325. * the following creates a static link to the route:
  3326. * `<a routerLink="/user/bob">link to user component</a>`
  3327. *
  3328. * You can use dynamic values to generate the link.
  3329. * For a dynamic link, pass an array of path segments,
  3330. * followed by the params for each segment.
  3331. * For example, `['/team', teamId, 'user', userName, {details: true}]`
  3332. * generates a link to `/team/11/user/bob;details=true`.
  3333. *
  3334. * Multiple static segments can be merged into one term and combined with dynamic segments.
  3335. * For example, `['/team/11/user', userName, {details: true}]`
  3336. *
  3337. * The input that you provide to the link is treated as a delta to the current URL.
  3338. * For instance, suppose the current URL is `/user/(box//aux:team)`.
  3339. * The link `<a [routerLink]="['/user/jim']">Jim</a>` creates the URL
  3340. * `/user/(jim//aux:team)`.
  3341. * See {@link Router#createUrlTree} for more information.
  3342. *
  3343. * @usageNotes
  3344. *
  3345. * You can use absolute or relative paths in a link, set query parameters,
  3346. * control how parameters are handled, and keep a history of navigation states.
  3347. *
  3348. * ### Relative link paths
  3349. *
  3350. * The first segment name can be prepended with `/`, `./`, or `../`.
  3351. * * If the first segment begins with `/`, the router looks up the route from the root of the
  3352. * app.
  3353. * * If the first segment begins with `./`, or doesn't begin with a slash, the router
  3354. * looks in the children of the current activated route.
  3355. * * If the first segment begins with `../`, the router goes up one level in the route tree.
  3356. *
  3357. * ### Setting and handling query params and fragments
  3358. *
  3359. * The following link adds a query parameter and a fragment to the generated URL:
  3360. *
  3361. * ```html
  3362. * <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
  3363. * link to user component
  3364. * </a>
  3365. * ```
  3366. * By default, the directive constructs the new URL using the given query parameters.
  3367. * The example generates the link: `/user/bob?debug=true#education`.
  3368. *
  3369. * You can instruct the directive to handle query parameters differently
  3370. * by specifying the `queryParamsHandling` option in the link.
  3371. * Allowed values are:
  3372. *
  3373. * - `'merge'`: Merge the given `queryParams` into the current query params.
  3374. * - `'preserve'`: Preserve the current query params.
  3375. *
  3376. * For example:
  3377. *
  3378. * ```html
  3379. * <a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" queryParamsHandling="merge">
  3380. * link to user component
  3381. * </a>
  3382. * ```
  3383. *
  3384. * `queryParams`, `fragment`, `queryParamsHandling`, `preserveFragment`, and `relativeTo`
  3385. * cannot be used when the `routerLink` input is a `UrlTree`.
  3386. *
  3387. * See {@link UrlCreationOptions#queryParamsHandling}.
  3388. *
  3389. * ### Preserving navigation history
  3390. *
  3391. * You can provide a `state` value to be persisted to the browser's
  3392. * [`History.state` property](https://developer.mozilla.org/en-US/docs/Web/API/History#Properties).
  3393. * For example:
  3394. *
  3395. * ```html
  3396. * <a [routerLink]="['/user/bob']" [state]="{tracingId: 123}">
  3397. * link to user component
  3398. * </a>
  3399. * ```
  3400. *
  3401. * Use {@link Router#getCurrentNavigation} to retrieve a saved
  3402. * navigation-state value. For example, to capture the `tracingId` during the `NavigationStart`
  3403. * event:
  3404. *
  3405. * ```ts
  3406. * // Get NavigationStart events
  3407. * router.events.pipe(filter(e => e instanceof NavigationStart)).subscribe(e => {
  3408. * const navigation = router.getCurrentNavigation();
  3409. * tracingService.trace({id: navigation.extras.state.tracingId});
  3410. * });
  3411. * ```
  3412. *
  3413. * @ngModule RouterModule
  3414. *
  3415. * @publicApi
  3416. */
  3417. declare class RouterLink implements OnChanges, OnDestroy {
  3418. private router;
  3419. private route;
  3420. private readonly tabIndexAttribute;
  3421. private readonly renderer;
  3422. private readonly el;
  3423. private locationStrategy?;
  3424. /**
  3425. * Represents an `href` attribute value applied to a host element,
  3426. * when a host element is `<a>`. For other tags, the value is `null`.
  3427. */
  3428. href: string | null;
  3429. /**
  3430. * Represents the `target` attribute on a host element.
  3431. * This is only used when the host element is an `<a>` tag.
  3432. */
  3433. target?: string;
  3434. /**
  3435. * Passed to {@link Router#createUrlTree} as part of the
  3436. * `UrlCreationOptions`.
  3437. * @see {@link UrlCreationOptions#queryParams}
  3438. * @see {@link Router#createUrlTree}
  3439. */
  3440. queryParams?: Params | null;
  3441. /**
  3442. * Passed to {@link Router#createUrlTree} as part of the
  3443. * `UrlCreationOptions`.
  3444. * @see {@link UrlCreationOptions#fragment}
  3445. * @see {@link Router#createUrlTree}
  3446. */
  3447. fragment?: string;
  3448. /**
  3449. * Passed to {@link Router#createUrlTree} as part of the
  3450. * `UrlCreationOptions`.
  3451. * @see {@link UrlCreationOptions#queryParamsHandling}
  3452. * @see {@link Router#createUrlTree}
  3453. */
  3454. queryParamsHandling?: QueryParamsHandling | null;
  3455. /**
  3456. * Passed to {@link Router#navigateByUrl} as part of the
  3457. * `NavigationBehaviorOptions`.
  3458. * @see {@link NavigationBehaviorOptions#state}
  3459. * @see {@link Router#navigateByUrl}
  3460. */
  3461. state?: {
  3462. [k: string]: any;
  3463. };
  3464. /**
  3465. * Passed to {@link Router#navigateByUrl} as part of the
  3466. * `NavigationBehaviorOptions`.
  3467. * @see {@link NavigationBehaviorOptions#info}
  3468. * @see {@link Router#navigateByUrl}
  3469. */
  3470. info?: unknown;
  3471. /**
  3472. * Passed to {@link Router#createUrlTree} as part of the
  3473. * `UrlCreationOptions`.
  3474. * Specify a value here when you do not want to use the default value
  3475. * for `routerLink`, which is the current activated route.
  3476. * Note that a value of `undefined` here will use the `routerLink` default.
  3477. * @see {@link UrlCreationOptions#relativeTo}
  3478. * @see {@link Router#createUrlTree}
  3479. */
  3480. relativeTo?: ActivatedRoute | null;
  3481. /** Whether a host element is an `<a>` tag. */
  3482. private isAnchorElement;
  3483. private subscription?;
  3484. constructor(router: Router, route: ActivatedRoute, tabIndexAttribute: string | null | undefined, renderer: Renderer2, el: ElementRef, locationStrategy?: LocationStrategy | undefined);
  3485. /**
  3486. * Passed to {@link Router#createUrlTree} as part of the
  3487. * `UrlCreationOptions`.
  3488. * @see {@link UrlCreationOptions#preserveFragment}
  3489. * @see {@link Router#createUrlTree}
  3490. */
  3491. preserveFragment: boolean;
  3492. /**
  3493. * Passed to {@link Router#navigateByUrl} as part of the
  3494. * `NavigationBehaviorOptions`.
  3495. * @see {@link NavigationBehaviorOptions#skipLocationChange}
  3496. * @see {@link Router#navigateByUrl}
  3497. */
  3498. skipLocationChange: boolean;
  3499. /**
  3500. * Passed to {@link Router#navigateByUrl} as part of the
  3501. * `NavigationBehaviorOptions`.
  3502. * @see {@link NavigationBehaviorOptions#replaceUrl}
  3503. * @see {@link Router#navigateByUrl}
  3504. */
  3505. replaceUrl: boolean;
  3506. /**
  3507. * Modifies the tab index if there was not a tabindex attribute on the element during
  3508. * instantiation.
  3509. */
  3510. private setTabIndexIfNotOnNativeEl;
  3511. /** @nodoc */
  3512. ngOnChanges(changes?: SimpleChanges): void;
  3513. private routerLinkInput;
  3514. /**
  3515. * Commands to pass to {@link Router#createUrlTree} or a `UrlTree`.
  3516. * - **array**: commands to pass to {@link Router#createUrlTree}.
  3517. * - **string**: shorthand for array of commands with just the string, i.e. `['/route']`
  3518. * - **UrlTree**: a `UrlTree` for this link rather than creating one from the commands
  3519. * and other inputs that correspond to properties of `UrlCreationOptions`.
  3520. * - **null|undefined**: effectively disables the `routerLink`
  3521. * @see {@link Router#createUrlTree}
  3522. */
  3523. set routerLink(commandsOrUrlTree: any[] | string | UrlTree | null | undefined);
  3524. /** @nodoc */
  3525. onClick(button: number, ctrlKey: boolean, shiftKey: boolean, altKey: boolean, metaKey: boolean): boolean;
  3526. /** @nodoc */
  3527. ngOnDestroy(): any;
  3528. private updateHref;
  3529. private applyAttributeValue;
  3530. get urlTree(): UrlTree | null;
  3531. static ɵfac: i0.ɵɵFactoryDeclaration<RouterLink, [null, null, { attribute: "tabindex"; }, null, null, null]>;
  3532. static ɵdir: i0.ɵɵDirectiveDeclaration<RouterLink, "[routerLink]", never, { "target": { "alias": "target"; "required": false; }; "queryParams": { "alias": "queryParams"; "required": false; }; "fragment": { "alias": "fragment"; "required": false; }; "queryParamsHandling": { "alias": "queryParamsHandling"; "required": false; }; "state": { "alias": "state"; "required": false; }; "info": { "alias": "info"; "required": false; }; "relativeTo": { "alias": "relativeTo"; "required": false; }; "preserveFragment": { "alias": "preserveFragment"; "required": false; }; "skipLocationChange": { "alias": "skipLocationChange"; "required": false; }; "replaceUrl": { "alias": "replaceUrl"; "required": false; }; "routerLink": { "alias": "routerLink"; "required": false; }; }, {}, never, never, true, never>;
  3533. static ngAcceptInputType_preserveFragment: unknown;
  3534. static ngAcceptInputType_skipLocationChange: unknown;
  3535. static ngAcceptInputType_replaceUrl: unknown;
  3536. }
  3537. /**
  3538. *
  3539. * @description
  3540. *
  3541. * Tracks whether the linked route of an element is currently active, and allows you
  3542. * to specify one or more CSS classes to add to the element when the linked route
  3543. * is active.
  3544. *
  3545. * Use this directive to create a visual distinction for elements associated with an active route.
  3546. * For example, the following code highlights the word "Bob" when the router
  3547. * activates the associated route:
  3548. *
  3549. * ```html
  3550. * <a routerLink="/user/bob" routerLinkActive="active-link">Bob</a>
  3551. * ```
  3552. *
  3553. * Whenever the URL is either '/user' or '/user/bob', the "active-link" class is
  3554. * added to the anchor tag. If the URL changes, the class is removed.
  3555. *
  3556. * You can set more than one class using a space-separated string or an array.
  3557. * For example:
  3558. *
  3559. * ```html
  3560. * <a routerLink="/user/bob" routerLinkActive="class1 class2">Bob</a>
  3561. * <a routerLink="/user/bob" [routerLinkActive]="['class1', 'class2']">Bob</a>
  3562. * ```
  3563. *
  3564. * To add the classes only when the URL matches the link exactly, add the option `exact: true`:
  3565. *
  3566. * ```html
  3567. * <a routerLink="/user/bob" routerLinkActive="active-link" [routerLinkActiveOptions]="{exact:
  3568. * true}">Bob</a>
  3569. * ```
  3570. *
  3571. * To directly check the `isActive` status of the link, assign the `RouterLinkActive`
  3572. * instance to a template variable.
  3573. * For example, the following checks the status without assigning any CSS classes:
  3574. *
  3575. * ```html
  3576. * <a routerLink="/user/bob" routerLinkActive #rla="routerLinkActive">
  3577. * Bob {{ rla.isActive ? '(already open)' : ''}}
  3578. * </a>
  3579. * ```
  3580. *
  3581. * You can apply the `RouterLinkActive` directive to an ancestor of linked elements.
  3582. * For example, the following sets the active-link class on the `<div>` parent tag
  3583. * when the URL is either '/user/jim' or '/user/bob'.
  3584. *
  3585. * ```html
  3586. * <div routerLinkActive="active-link" [routerLinkActiveOptions]="{exact: true}">
  3587. * <a routerLink="/user/jim">Jim</a>
  3588. * <a routerLink="/user/bob">Bob</a>
  3589. * </div>
  3590. * ```
  3591. *
  3592. * The `RouterLinkActive` directive can also be used to set the aria-current attribute
  3593. * to provide an alternative distinction for active elements to visually impaired users.
  3594. *
  3595. * For example, the following code adds the 'active' class to the Home Page link when it is
  3596. * indeed active and in such case also sets its aria-current attribute to 'page':
  3597. *
  3598. * ```html
  3599. * <a routerLink="/" routerLinkActive="active" ariaCurrentWhenActive="page">Home Page</a>
  3600. * ```
  3601. *
  3602. * @ngModule RouterModule
  3603. *
  3604. * @publicApi
  3605. */
  3606. declare class RouterLinkActive implements OnChanges, OnDestroy, AfterContentInit {
  3607. private router;
  3608. private element;
  3609. private renderer;
  3610. private readonly cdr;
  3611. private link?;
  3612. links: QueryList<RouterLink>;
  3613. private classes;
  3614. private routerEventsSubscription;
  3615. private linkInputChangesSubscription?;
  3616. private _isActive;
  3617. get isActive(): boolean;
  3618. /**
  3619. * Options to configure how to determine if the router link is active.
  3620. *
  3621. * These options are passed to the `Router.isActive()` function.
  3622. *
  3623. * @see {@link Router#isActive}
  3624. */
  3625. routerLinkActiveOptions: {
  3626. exact: boolean;
  3627. } | IsActiveMatchOptions;
  3628. /**
  3629. * Aria-current attribute to apply when the router link is active.
  3630. *
  3631. * Possible values: `'page'` | `'step'` | `'location'` | `'date'` | `'time'` | `true` | `false`.
  3632. *
  3633. * @see {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current}
  3634. */
  3635. ariaCurrentWhenActive?: 'page' | 'step' | 'location' | 'date' | 'time' | true | false;
  3636. /**
  3637. *
  3638. * You can use the output `isActiveChange` to get notified each time the link becomes
  3639. * active or inactive.
  3640. *
  3641. * Emits:
  3642. * true -> Route is active
  3643. * false -> Route is inactive
  3644. *
  3645. * ```html
  3646. * <a
  3647. * routerLink="/user/bob"
  3648. * routerLinkActive="active-link"
  3649. * (isActiveChange)="this.onRouterLinkActive($event)">Bob</a>
  3650. * ```
  3651. */
  3652. readonly isActiveChange: EventEmitter<boolean>;
  3653. constructor(router: Router, element: ElementRef, renderer: Renderer2, cdr: ChangeDetectorRef, link?: RouterLink | undefined);
  3654. /** @nodoc */
  3655. ngAfterContentInit(): void;
  3656. private subscribeToEachLinkOnChanges;
  3657. set routerLinkActive(data: string[] | string);
  3658. /** @nodoc */
  3659. ngOnChanges(changes: SimpleChanges): void;
  3660. /** @nodoc */
  3661. ngOnDestroy(): void;
  3662. private update;
  3663. private isLinkActive;
  3664. private hasActiveLinks;
  3665. static ɵfac: i0.ɵɵFactoryDeclaration<RouterLinkActive, [null, null, null, null, { optional: true; }]>;
  3666. static ɵdir: i0.ɵɵDirectiveDeclaration<RouterLinkActive, "[routerLinkActive]", ["routerLinkActive"], { "routerLinkActiveOptions": { "alias": "routerLinkActiveOptions"; "required": false; }; "ariaCurrentWhenActive": { "alias": "ariaCurrentWhenActive"; "required": false; }; "routerLinkActive": { "alias": "routerLinkActive"; "required": false; }; }, { "isActiveChange": "isActiveChange"; }, ["links"], never, true, never>;
  3667. }
  3668. /**
  3669. * Options to configure the View Transitions integration in the Router.
  3670. *
  3671. * @experimental
  3672. * @publicApi
  3673. * @see withViewTransitions
  3674. */
  3675. interface ViewTransitionsFeatureOptions {
  3676. /**
  3677. * Skips the very first call to `startViewTransition`. This can be useful for disabling the
  3678. * animation during the application's initial loading phase.
  3679. */
  3680. skipInitialTransition?: boolean;
  3681. /**
  3682. * A function to run after the `ViewTransition` is created.
  3683. *
  3684. * This function is run in an injection context and can use `inject`.
  3685. */
  3686. onViewTransitionCreated?: (transitionInfo: ViewTransitionInfo) => void;
  3687. }
  3688. /**
  3689. * The information passed to the `onViewTransitionCreated` function provided in the
  3690. * `withViewTransitions` feature options.
  3691. *
  3692. * @publicApi
  3693. * @experimental
  3694. */
  3695. interface ViewTransitionInfo {
  3696. /**
  3697. * The `ViewTransition` returned by the call to `startViewTransition`.
  3698. * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition
  3699. */
  3700. transition: {
  3701. /**
  3702. * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition/finished
  3703. */
  3704. finished: Promise<void>;
  3705. /**
  3706. * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition/ready
  3707. */
  3708. ready: Promise<void>;
  3709. /**
  3710. * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition/updateCallbackDone
  3711. */
  3712. updateCallbackDone: Promise<void>;
  3713. /**
  3714. * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition/skipTransition
  3715. */
  3716. skipTransition(): void;
  3717. };
  3718. /**
  3719. * The `ActivatedRouteSnapshot` that the navigation is transitioning from.
  3720. */
  3721. from: ActivatedRouteSnapshot;
  3722. /**
  3723. * The `ActivatedRouteSnapshot` that the navigation is transitioning to.
  3724. */
  3725. to: ActivatedRouteSnapshot;
  3726. }
  3727. /**
  3728. * Provides a strategy for setting the page title after a router navigation.
  3729. *
  3730. * The built-in implementation traverses the router state snapshot and finds the deepest primary
  3731. * outlet with `title` property. Given the `Routes` below, navigating to
  3732. * `/base/child(popup:aux)` would result in the document title being set to "child".
  3733. * ```ts
  3734. * [
  3735. * {path: 'base', title: 'base', children: [
  3736. * {path: 'child', title: 'child'},
  3737. * ],
  3738. * {path: 'aux', outlet: 'popup', title: 'popupTitle'}
  3739. * ]
  3740. * ```
  3741. *
  3742. * This class can be used as a base class for custom title strategies. That is, you can create your
  3743. * own class that extends the `TitleStrategy`. Note that in the above example, the `title`
  3744. * from the named outlet is never used. However, a custom strategy might be implemented to
  3745. * incorporate titles in named outlets.
  3746. *
  3747. * @publicApi
  3748. * @see [Page title guide](guide/routing/common-router-tasks#setting-the-page-title)
  3749. */
  3750. declare abstract class TitleStrategy {
  3751. /** Performs the application title update. */
  3752. abstract updateTitle(snapshot: RouterStateSnapshot): void;
  3753. /**
  3754. * @returns The `title` of the deepest primary route.
  3755. */
  3756. buildTitle(snapshot: RouterStateSnapshot): string | undefined;
  3757. /**
  3758. * Given an `ActivatedRouteSnapshot`, returns the final value of the
  3759. * `Route.title` property, which can either be a static string or a resolved value.
  3760. */
  3761. getResolvedTitleForRoute(snapshot: ActivatedRouteSnapshot): any;
  3762. static ɵfac: i0.ɵɵFactoryDeclaration<TitleStrategy, never>;
  3763. static ɵprov: i0.ɵɵInjectableDeclaration<TitleStrategy>;
  3764. }
  3765. /**
  3766. * The default `TitleStrategy` used by the router that updates the title using the `Title` service.
  3767. */
  3768. declare class DefaultTitleStrategy extends TitleStrategy {
  3769. readonly title: Title;
  3770. constructor(title: Title);
  3771. /**
  3772. * Sets the title of the browser to the given value.
  3773. *
  3774. * @param title The `pageTitle` from the deepest primary route.
  3775. */
  3776. updateTitle(snapshot: RouterStateSnapshot): void;
  3777. static ɵfac: i0.ɵɵFactoryDeclaration<DefaultTitleStrategy, never>;
  3778. static ɵprov: i0.ɵɵInjectableDeclaration<DefaultTitleStrategy>;
  3779. }
  3780. /**
  3781. * Allowed values in an `ExtraOptions` object that configure
  3782. * when the router performs the initial navigation operation.
  3783. *
  3784. * * 'enabledNonBlocking' - (default) The initial navigation starts after the
  3785. * root component has been created. The bootstrap is not blocked on the completion of the initial
  3786. * navigation.
  3787. * * 'enabledBlocking' - The initial navigation starts before the root component is created.
  3788. * The bootstrap is blocked until the initial navigation is complete. This value should be set in
  3789. * case you use [server-side rendering](guide/ssr), but do not enable [hydration](guide/hydration)
  3790. * for your application.
  3791. * * 'disabled' - The initial navigation is not performed. The location listener is set up before
  3792. * the root component gets created. Use if there is a reason to have
  3793. * more control over when the router starts its initial navigation due to some complex
  3794. * initialization logic.
  3795. *
  3796. * @see {@link /api/router/RouterModule#forRoot forRoot}
  3797. *
  3798. * @publicApi
  3799. */
  3800. type InitialNavigation = 'disabled' | 'enabledBlocking' | 'enabledNonBlocking';
  3801. /**
  3802. * Extra configuration options that can be used with the `withRouterConfig` function.
  3803. *
  3804. * @publicApi
  3805. */
  3806. interface RouterConfigOptions {
  3807. /**
  3808. * Configures how the Router attempts to restore state when a navigation is cancelled.
  3809. *
  3810. * 'replace' - Always uses `location.replaceState` to set the browser state to the state of the
  3811. * router before the navigation started. This means that if the URL of the browser is updated
  3812. * _before_ the navigation is canceled, the Router will simply replace the item in history rather
  3813. * than trying to restore to the previous location in the session history. This happens most
  3814. * frequently with `urlUpdateStrategy: 'eager'` and navigations with the browser back/forward
  3815. * buttons.
  3816. *
  3817. * 'computed' - Will attempt to return to the same index in the session history that corresponds
  3818. * to the Angular route when the navigation gets cancelled. For example, if the browser back
  3819. * button is clicked and the navigation is cancelled, the Router will trigger a forward navigation
  3820. * and vice versa.
  3821. *
  3822. * Note: the 'computed' option is incompatible with any `UrlHandlingStrategy` which only
  3823. * handles a portion of the URL because the history restoration navigates to the previous place in
  3824. * the browser history rather than simply resetting a portion of the URL.
  3825. *
  3826. * The default value is `replace` when not set.
  3827. */
  3828. canceledNavigationResolution?: 'replace' | 'computed';
  3829. /**
  3830. * Configures the default for handling a navigation request to the current URL.
  3831. *
  3832. * If unset, the `Router` will use `'ignore'`.
  3833. *
  3834. * @see {@link OnSameUrlNavigation}
  3835. */
  3836. onSameUrlNavigation?: OnSameUrlNavigation;
  3837. /**
  3838. * Defines how the router merges parameters, data, and resolved data from parent to child
  3839. * routes.
  3840. *
  3841. * By default ('emptyOnly'), a route inherits the parent route's parameters when the route itself
  3842. * has an empty path (meaning its configured with path: '') or when the parent route doesn't have
  3843. * any component set.
  3844. *
  3845. * Set to 'always' to enable unconditional inheritance of parent parameters.
  3846. *
  3847. * Note that when dealing with matrix parameters, "parent" refers to the parent `Route`
  3848. * config which does not necessarily mean the "URL segment to the left". When the `Route` `path`
  3849. * contains multiple segments, the matrix parameters must appear on the last segment. For example,
  3850. * matrix parameters for `{path: 'a/b', component: MyComp}` should appear as `a/b;foo=bar` and not
  3851. * `a;foo=bar/b`.
  3852. *
  3853. */
  3854. paramsInheritanceStrategy?: 'emptyOnly' | 'always';
  3855. /**
  3856. * Defines when the router updates the browser URL. By default ('deferred'),
  3857. * update after successful navigation.
  3858. * Set to 'eager' if prefer to update the URL at the beginning of navigation.
  3859. * Updating the URL early allows you to handle a failure of navigation by
  3860. * showing an error message with the URL that failed.
  3861. */
  3862. urlUpdateStrategy?: 'deferred' | 'eager';
  3863. /**
  3864. * The default strategy to use for handling query params in `Router.createUrlTree` when one is not provided.
  3865. *
  3866. * The `createUrlTree` method is used internally by `Router.navigate` and `RouterLink`.
  3867. * Note that `QueryParamsHandling` does not apply to `Router.navigateByUrl`.
  3868. *
  3869. * When neither the default nor the queryParamsHandling option is specified in the call to `createUrlTree`,
  3870. * the current parameters will be replaced by new parameters.
  3871. *
  3872. * @see {@link Router#createUrlTree}
  3873. * @see {@link QueryParamsHandling}
  3874. */
  3875. defaultQueryParamsHandling?: QueryParamsHandling;
  3876. /**
  3877. * When `true`, the `Promise` will instead resolve with `false`, as it does with other failed
  3878. * navigations (for example, when guards are rejected).
  3879. * Otherwise the `Promise` returned by the Router's navigation with be rejected
  3880. * if an error occurs.
  3881. */
  3882. resolveNavigationPromiseOnError?: boolean;
  3883. }
  3884. /**
  3885. * Configuration options for the scrolling feature which can be used with `withInMemoryScrolling`
  3886. * function.
  3887. *
  3888. * @publicApi
  3889. */
  3890. interface InMemoryScrollingOptions {
  3891. /**
  3892. * When set to 'enabled', scrolls to the anchor element when the URL has a fragment.
  3893. * Anchor scrolling is disabled by default.
  3894. *
  3895. * Anchor scrolling does not happen on 'popstate'. Instead, we restore the position
  3896. * that we stored or scroll to the top.
  3897. */
  3898. anchorScrolling?: 'disabled' | 'enabled';
  3899. /**
  3900. * Configures if the scroll position needs to be restored when navigating back.
  3901. *
  3902. * * 'disabled'- (Default) Does nothing. Scroll position is maintained on navigation.
  3903. * * 'top'- Sets the scroll position to x = 0, y = 0 on all navigation.
  3904. * * 'enabled'- Restores the previous scroll position on backward navigation, else sets the
  3905. * position to the anchor if one is provided, or sets the scroll position to [0, 0] (forward
  3906. * navigation). This option will be the default in the future.
  3907. *
  3908. * You can implement custom scroll restoration behavior by adapting the enabled behavior as
  3909. * in the following example.
  3910. *
  3911. * ```ts
  3912. * class AppComponent {
  3913. * movieData: any;
  3914. *
  3915. * constructor(private router: Router, private viewportScroller: ViewportScroller,
  3916. * changeDetectorRef: ChangeDetectorRef) {
  3917. * router.events.pipe(filter((event: Event): event is Scroll => event instanceof Scroll)
  3918. * ).subscribe(e => {
  3919. * fetch('http://example.com/movies.json').then(response => {
  3920. * this.movieData = response.json();
  3921. * // update the template with the data before restoring scroll
  3922. * changeDetectorRef.detectChanges();
  3923. *
  3924. * if (e.position) {
  3925. * viewportScroller.scrollToPosition(e.position);
  3926. * }
  3927. * });
  3928. * });
  3929. * }
  3930. * }
  3931. * ```
  3932. */
  3933. scrollPositionRestoration?: 'disabled' | 'enabled' | 'top';
  3934. }
  3935. /**
  3936. * A set of configuration options for a router module, provided in the
  3937. * `forRoot()` method.
  3938. *
  3939. * @see {@link /api/router/routerModule#forRoot forRoot}
  3940. *
  3941. *
  3942. * @publicApi
  3943. */
  3944. interface ExtraOptions extends InMemoryScrollingOptions, RouterConfigOptions {
  3945. /**
  3946. * When true, log all internal navigation events to the console.
  3947. * Use for debugging.
  3948. */
  3949. enableTracing?: boolean;
  3950. /**
  3951. * When true, enable the location strategy that uses the URL fragment
  3952. * instead of the history API.
  3953. */
  3954. useHash?: boolean;
  3955. /**
  3956. * One of `enabled`, `enabledBlocking`, `enabledNonBlocking` or `disabled`.
  3957. * When set to `enabled` or `enabledBlocking`, the initial navigation starts before the root
  3958. * component is created. The bootstrap is blocked until the initial navigation is complete. This
  3959. * value should be set in case you use [server-side rendering](guide/ssr), but do not enable
  3960. * [hydration](guide/hydration) for your application. When set to `enabledNonBlocking`,
  3961. * the initial navigation starts after the root component has been created.
  3962. * The bootstrap is not blocked on the completion of the initial navigation. When set to
  3963. * `disabled`, the initial navigation is not performed. The location listener is set up before the
  3964. * root component gets created. Use if there is a reason to have more control over when the router
  3965. * starts its initial navigation due to some complex initialization logic.
  3966. */
  3967. initialNavigation?: InitialNavigation;
  3968. /**
  3969. * When true, enables binding information from the `Router` state directly to the inputs of the
  3970. * component in `Route` configurations.
  3971. */
  3972. bindToComponentInputs?: boolean;
  3973. /**
  3974. * When true, enables view transitions in the Router by running the route activation and
  3975. * deactivation inside of `document.startViewTransition`.
  3976. *
  3977. * @see https://developer.chrome.com/docs/web-platform/view-transitions/
  3978. * @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
  3979. * @experimental
  3980. */
  3981. enableViewTransitions?: boolean;
  3982. /**
  3983. * A custom error handler for failed navigations.
  3984. * If the handler returns a value, the navigation Promise is resolved with this value.
  3985. * If the handler throws an exception, the navigation Promise is rejected with the exception.
  3986. *
  3987. * @see RouterConfigOptions
  3988. */
  3989. errorHandler?: (error: any) => RedirectCommand | any;
  3990. /**
  3991. * Configures a preloading strategy.
  3992. * One of `PreloadAllModules` or `NoPreloading` (the default).
  3993. */
  3994. preloadingStrategy?: any;
  3995. /**
  3996. * Configures the scroll offset the router will use when scrolling to an element.
  3997. *
  3998. * When given a tuple with x and y position value,
  3999. * the router uses that offset each time it scrolls.
  4000. * When given a function, the router invokes the function every time
  4001. * it restores scroll position.
  4002. */
  4003. scrollOffset?: [number, number] | (() => [number, number]);
  4004. }
  4005. /**
  4006. * A DI token for the router service.
  4007. *
  4008. * @publicApi
  4009. */
  4010. declare const ROUTER_CONFIGURATION: InjectionToken<ExtraOptions>;
  4011. /**
  4012. * The DI token for a router configuration.
  4013. *
  4014. * `ROUTES` is a low level API for router configuration via dependency injection.
  4015. *
  4016. * We recommend that in almost all cases to use higher level APIs such as `RouterModule.forRoot()`,
  4017. * `provideRouter`, or `Router.resetConfig()`.
  4018. *
  4019. * @publicApi
  4020. */
  4021. declare const ROUTES: InjectionToken<Route[][]>;
  4022. declare class RouterConfigLoader {
  4023. private componentLoaders;
  4024. private childrenLoaders;
  4025. onLoadStartListener?: (r: Route) => void;
  4026. onLoadEndListener?: (r: Route) => void;
  4027. private readonly compiler;
  4028. loadComponent(route: Route): Observable<Type<unknown>>;
  4029. loadChildren(parentInjector: Injector, route: Route): Observable<LoadedRouterConfig>;
  4030. static ɵfac: i0.ɵɵFactoryDeclaration<RouterConfigLoader, never>;
  4031. static ɵprov: i0.ɵɵInjectableDeclaration<RouterConfigLoader>;
  4032. }
  4033. /**
  4034. * Executes a `route.loadChildren` callback and converts the result to an array of child routes and
  4035. * an injector if that callback returned a module.
  4036. *
  4037. * This function is used for the route discovery during prerendering
  4038. * in @angular-devkit/build-angular. If there are any updates to the contract here, it will require
  4039. * an update to the extractor.
  4040. */
  4041. declare function loadChildren(route: Route, compiler: Compiler, parentInjector: Injector, onLoadEndListener?: (r: Route) => void): Observable<LoadedRouterConfig>;
  4042. /**
  4043. * @description
  4044. *
  4045. * Provides a preloading strategy.
  4046. *
  4047. * @publicApi
  4048. */
  4049. declare abstract class PreloadingStrategy {
  4050. abstract preload(route: Route, fn: () => Observable<any>): Observable<any>;
  4051. }
  4052. /**
  4053. * @description
  4054. *
  4055. * Provides a preloading strategy that preloads all modules as quickly as possible.
  4056. *
  4057. * ```ts
  4058. * RouterModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules})
  4059. * ```
  4060. *
  4061. * @publicApi
  4062. */
  4063. declare class PreloadAllModules implements PreloadingStrategy {
  4064. preload(route: Route, fn: () => Observable<any>): Observable<any>;
  4065. static ɵfac: i0.ɵɵFactoryDeclaration<PreloadAllModules, never>;
  4066. static ɵprov: i0.ɵɵInjectableDeclaration<PreloadAllModules>;
  4067. }
  4068. /**
  4069. * @description
  4070. *
  4071. * Provides a preloading strategy that does not preload any modules.
  4072. *
  4073. * This strategy is enabled by default.
  4074. *
  4075. * @publicApi
  4076. */
  4077. declare class NoPreloading implements PreloadingStrategy {
  4078. preload(route: Route, fn: () => Observable<any>): Observable<any>;
  4079. static ɵfac: i0.ɵɵFactoryDeclaration<NoPreloading, never>;
  4080. static ɵprov: i0.ɵɵInjectableDeclaration<NoPreloading>;
  4081. }
  4082. /**
  4083. * The preloader optimistically loads all router configurations to
  4084. * make navigations into lazily-loaded sections of the application faster.
  4085. *
  4086. * The preloader runs in the background. When the router bootstraps, the preloader
  4087. * starts listening to all navigation events. After every such event, the preloader
  4088. * will check if any configurations can be loaded lazily.
  4089. *
  4090. * If a route is protected by `canLoad` guards, the preloaded will not load it.
  4091. *
  4092. * @publicApi
  4093. */
  4094. declare class RouterPreloader implements OnDestroy {
  4095. private router;
  4096. private injector;
  4097. private preloadingStrategy;
  4098. private loader;
  4099. private subscription?;
  4100. constructor(router: Router, compiler: Compiler, injector: EnvironmentInjector, preloadingStrategy: PreloadingStrategy, loader: RouterConfigLoader);
  4101. setUpPreloading(): void;
  4102. preload(): Observable<any>;
  4103. /** @nodoc */
  4104. ngOnDestroy(): void;
  4105. private processRoutes;
  4106. private preloadConfig;
  4107. static ɵfac: i0.ɵɵFactoryDeclaration<RouterPreloader, never>;
  4108. static ɵprov: i0.ɵɵInjectableDeclaration<RouterPreloader>;
  4109. }
  4110. /**
  4111. * Sets up providers necessary to enable `Router` functionality for the application.
  4112. * Allows to configure a set of routes as well as extra features that should be enabled.
  4113. *
  4114. * @usageNotes
  4115. *
  4116. * Basic example of how you can add a Router to your application:
  4117. * ```ts
  4118. * const appRoutes: Routes = [];
  4119. * bootstrapApplication(AppComponent, {
  4120. * providers: [provideRouter(appRoutes)]
  4121. * });
  4122. * ```
  4123. *
  4124. * You can also enable optional features in the Router by adding functions from the `RouterFeatures`
  4125. * type:
  4126. * ```ts
  4127. * const appRoutes: Routes = [];
  4128. * bootstrapApplication(AppComponent,
  4129. * {
  4130. * providers: [
  4131. * provideRouter(appRoutes,
  4132. * withDebugTracing(),
  4133. * withRouterConfig({paramsInheritanceStrategy: 'always'}))
  4134. * ]
  4135. * }
  4136. * );
  4137. * ```
  4138. *
  4139. * @see {@link RouterFeatures}
  4140. *
  4141. * @publicApi
  4142. * @param routes A set of `Route`s to use for the application routing table.
  4143. * @param features Optional features to configure additional router behaviors.
  4144. * @returns A set of providers to setup a Router.
  4145. */
  4146. declare function provideRouter(routes: Routes, ...features: RouterFeatures[]): EnvironmentProviders;
  4147. /**
  4148. * Helper type to represent a Router feature.
  4149. *
  4150. * @publicApi
  4151. */
  4152. interface RouterFeature<FeatureKind extends RouterFeatureKind> {
  4153. ɵkind: FeatureKind;
  4154. ɵproviders: Provider[];
  4155. }
  4156. /**
  4157. * Registers a DI provider for a set of routes.
  4158. * @param routes The route configuration to provide.
  4159. *
  4160. * @usageNotes
  4161. *
  4162. * ```ts
  4163. * @NgModule({
  4164. * providers: [provideRoutes(ROUTES)]
  4165. * })
  4166. * class LazyLoadedChildModule {}
  4167. * ```
  4168. *
  4169. * @deprecated If necessary, provide routes using the `ROUTES` `InjectionToken`.
  4170. * @see {@link ROUTES}
  4171. * @publicApi
  4172. */
  4173. declare function provideRoutes(routes: Routes): Provider[];
  4174. /**
  4175. * A type alias for providers returned by `withInMemoryScrolling` for use with `provideRouter`.
  4176. *
  4177. * @see {@link withInMemoryScrolling}
  4178. * @see {@link provideRouter}
  4179. *
  4180. * @publicApi
  4181. */
  4182. type InMemoryScrollingFeature = RouterFeature<RouterFeatureKind.InMemoryScrollingFeature>;
  4183. /**
  4184. * Enables customizable scrolling behavior for router navigations.
  4185. *
  4186. * @usageNotes
  4187. *
  4188. * Basic example of how you can enable scrolling feature:
  4189. * ```ts
  4190. * const appRoutes: Routes = [];
  4191. * bootstrapApplication(AppComponent,
  4192. * {
  4193. * providers: [
  4194. * provideRouter(appRoutes, withInMemoryScrolling())
  4195. * ]
  4196. * }
  4197. * );
  4198. * ```
  4199. *
  4200. * @see {@link provideRouter}
  4201. * @see {@link ViewportScroller}
  4202. *
  4203. * @publicApi
  4204. * @param options Set of configuration parameters to customize scrolling behavior, see
  4205. * `InMemoryScrollingOptions` for additional information.
  4206. * @returns A set of providers for use with `provideRouter`.
  4207. */
  4208. declare function withInMemoryScrolling(options?: InMemoryScrollingOptions): InMemoryScrollingFeature;
  4209. /**
  4210. * A type alias for providers returned by `withEnabledBlockingInitialNavigation` for use with
  4211. * `provideRouter`.
  4212. *
  4213. * @see {@link withEnabledBlockingInitialNavigation}
  4214. * @see {@link provideRouter}
  4215. *
  4216. * @publicApi
  4217. */
  4218. type EnabledBlockingInitialNavigationFeature = RouterFeature<RouterFeatureKind.EnabledBlockingInitialNavigationFeature>;
  4219. /**
  4220. * A type alias for providers returned by `withEnabledBlockingInitialNavigation` or
  4221. * `withDisabledInitialNavigation` functions for use with `provideRouter`.
  4222. *
  4223. * @see {@link withEnabledBlockingInitialNavigation}
  4224. * @see {@link withDisabledInitialNavigation}
  4225. * @see {@link provideRouter}
  4226. *
  4227. * @publicApi
  4228. */
  4229. type InitialNavigationFeature = EnabledBlockingInitialNavigationFeature | DisabledInitialNavigationFeature;
  4230. /**
  4231. * Configures initial navigation to start before the root component is created.
  4232. *
  4233. * The bootstrap is blocked until the initial navigation is complete. This should be set in case
  4234. * you use [server-side rendering](guide/ssr), but do not enable [hydration](guide/hydration) for
  4235. * your application.
  4236. *
  4237. * @usageNotes
  4238. *
  4239. * Basic example of how you can enable this navigation behavior:
  4240. * ```ts
  4241. * const appRoutes: Routes = [];
  4242. * bootstrapApplication(AppComponent,
  4243. * {
  4244. * providers: [
  4245. * provideRouter(appRoutes, withEnabledBlockingInitialNavigation())
  4246. * ]
  4247. * }
  4248. * );
  4249. * ```
  4250. *
  4251. * @see {@link provideRouter}
  4252. *
  4253. * @publicApi
  4254. * @returns A set of providers for use with `provideRouter`.
  4255. */
  4256. declare function withEnabledBlockingInitialNavigation(): EnabledBlockingInitialNavigationFeature;
  4257. /**
  4258. * A type alias for providers returned by `withDisabledInitialNavigation` for use with
  4259. * `provideRouter`.
  4260. *
  4261. * @see {@link withDisabledInitialNavigation}
  4262. * @see {@link provideRouter}
  4263. *
  4264. * @publicApi
  4265. */
  4266. type DisabledInitialNavigationFeature = RouterFeature<RouterFeatureKind.DisabledInitialNavigationFeature>;
  4267. /**
  4268. * Disables initial navigation.
  4269. *
  4270. * Use if there is a reason to have more control over when the router starts its initial navigation
  4271. * due to some complex initialization logic.
  4272. *
  4273. * @usageNotes
  4274. *
  4275. * Basic example of how you can disable initial navigation:
  4276. * ```ts
  4277. * const appRoutes: Routes = [];
  4278. * bootstrapApplication(AppComponent,
  4279. * {
  4280. * providers: [
  4281. * provideRouter(appRoutes, withDisabledInitialNavigation())
  4282. * ]
  4283. * }
  4284. * );
  4285. * ```
  4286. *
  4287. * @see {@link provideRouter}
  4288. *
  4289. * @returns A set of providers for use with `provideRouter`.
  4290. *
  4291. * @publicApi
  4292. */
  4293. declare function withDisabledInitialNavigation(): DisabledInitialNavigationFeature;
  4294. /**
  4295. * A type alias for providers returned by `withDebugTracing` for use with `provideRouter`.
  4296. *
  4297. * @see {@link withDebugTracing}
  4298. * @see {@link provideRouter}
  4299. *
  4300. * @publicApi
  4301. */
  4302. type DebugTracingFeature = RouterFeature<RouterFeatureKind.DebugTracingFeature>;
  4303. /**
  4304. * Enables logging of all internal navigation events to the console.
  4305. * Extra logging might be useful for debugging purposes to inspect Router event sequence.
  4306. *
  4307. * @usageNotes
  4308. *
  4309. * Basic example of how you can enable debug tracing:
  4310. * ```ts
  4311. * const appRoutes: Routes = [];
  4312. * bootstrapApplication(AppComponent,
  4313. * {
  4314. * providers: [
  4315. * provideRouter(appRoutes, withDebugTracing())
  4316. * ]
  4317. * }
  4318. * );
  4319. * ```
  4320. *
  4321. * @see {@link provideRouter}
  4322. *
  4323. * @returns A set of providers for use with `provideRouter`.
  4324. *
  4325. * @publicApi
  4326. */
  4327. declare function withDebugTracing(): DebugTracingFeature;
  4328. /**
  4329. * A type alias that represents a feature which enables preloading in Router.
  4330. * The type is used to describe the return value of the `withPreloading` function.
  4331. *
  4332. * @see {@link withPreloading}
  4333. * @see {@link provideRouter}
  4334. *
  4335. * @publicApi
  4336. */
  4337. type PreloadingFeature = RouterFeature<RouterFeatureKind.PreloadingFeature>;
  4338. /**
  4339. * Allows to configure a preloading strategy to use. The strategy is configured by providing a
  4340. * reference to a class that implements a `PreloadingStrategy`.
  4341. *
  4342. * @usageNotes
  4343. *
  4344. * Basic example of how you can configure preloading:
  4345. * ```ts
  4346. * const appRoutes: Routes = [];
  4347. * bootstrapApplication(AppComponent,
  4348. * {
  4349. * providers: [
  4350. * provideRouter(appRoutes, withPreloading(PreloadAllModules))
  4351. * ]
  4352. * }
  4353. * );
  4354. * ```
  4355. *
  4356. * @see {@link provideRouter}
  4357. *
  4358. * @param preloadingStrategy A reference to a class that implements a `PreloadingStrategy` that
  4359. * should be used.
  4360. * @returns A set of providers for use with `provideRouter`.
  4361. *
  4362. * @publicApi
  4363. */
  4364. declare function withPreloading(preloadingStrategy: Type<PreloadingStrategy>): PreloadingFeature;
  4365. /**
  4366. * A type alias for providers returned by `withRouterConfig` for use with `provideRouter`.
  4367. *
  4368. * @see {@link withRouterConfig}
  4369. * @see {@link provideRouter}
  4370. *
  4371. * @publicApi
  4372. */
  4373. type RouterConfigurationFeature = RouterFeature<RouterFeatureKind.RouterConfigurationFeature>;
  4374. /**
  4375. * Allows to provide extra parameters to configure Router.
  4376. *
  4377. * @usageNotes
  4378. *
  4379. * Basic example of how you can provide extra configuration options:
  4380. * ```ts
  4381. * const appRoutes: Routes = [];
  4382. * bootstrapApplication(AppComponent,
  4383. * {
  4384. * providers: [
  4385. * provideRouter(appRoutes, withRouterConfig({
  4386. * onSameUrlNavigation: 'reload'
  4387. * }))
  4388. * ]
  4389. * }
  4390. * );
  4391. * ```
  4392. *
  4393. * @see {@link provideRouter}
  4394. *
  4395. * @param options A set of parameters to configure Router, see `RouterConfigOptions` for
  4396. * additional information.
  4397. * @returns A set of providers for use with `provideRouter`.
  4398. *
  4399. * @publicApi
  4400. */
  4401. declare function withRouterConfig(options: RouterConfigOptions): RouterConfigurationFeature;
  4402. /**
  4403. * A type alias for providers returned by `withHashLocation` for use with `provideRouter`.
  4404. *
  4405. * @see {@link withHashLocation}
  4406. * @see {@link provideRouter}
  4407. *
  4408. * @publicApi
  4409. */
  4410. type RouterHashLocationFeature = RouterFeature<RouterFeatureKind.RouterHashLocationFeature>;
  4411. /**
  4412. * Provides the location strategy that uses the URL fragment instead of the history API.
  4413. *
  4414. * @usageNotes
  4415. *
  4416. * Basic example of how you can use the hash location option:
  4417. * ```ts
  4418. * const appRoutes: Routes = [];
  4419. * bootstrapApplication(AppComponent,
  4420. * {
  4421. * providers: [
  4422. * provideRouter(appRoutes, withHashLocation())
  4423. * ]
  4424. * }
  4425. * );
  4426. * ```
  4427. *
  4428. * @see {@link provideRouter}
  4429. * @see {@link /api/common/HashLocationStrategy HashLocationStrategy}
  4430. *
  4431. * @returns A set of providers for use with `provideRouter`.
  4432. *
  4433. * @publicApi
  4434. */
  4435. declare function withHashLocation(): RouterHashLocationFeature;
  4436. /**
  4437. * A type alias for providers returned by `withNavigationErrorHandler` for use with `provideRouter`.
  4438. *
  4439. * @see {@link withNavigationErrorHandler}
  4440. * @see {@link provideRouter}
  4441. *
  4442. * @publicApi
  4443. */
  4444. type NavigationErrorHandlerFeature = RouterFeature<RouterFeatureKind.NavigationErrorHandlerFeature>;
  4445. /**
  4446. * Provides a function which is called when a navigation error occurs.
  4447. *
  4448. * This function is run inside application's [injection context](guide/di/dependency-injection-context)
  4449. * so you can use the [`inject`](api/core/inject) function.
  4450. *
  4451. * This function can return a `RedirectCommand` to convert the error to a redirect, similar to returning
  4452. * a `UrlTree` or `RedirectCommand` from a guard. This will also prevent the `Router` from emitting
  4453. * `NavigationError`; it will instead emit `NavigationCancel` with code NavigationCancellationCode.Redirect.
  4454. * Return values other than `RedirectCommand` are ignored and do not change any behavior with respect to
  4455. * how the `Router` handles the error.
  4456. *
  4457. * @usageNotes
  4458. *
  4459. * Basic example of how you can use the error handler option:
  4460. * ```ts
  4461. * const appRoutes: Routes = [];
  4462. * bootstrapApplication(AppComponent,
  4463. * {
  4464. * providers: [
  4465. * provideRouter(appRoutes, withNavigationErrorHandler((e: NavigationError) =>
  4466. * inject(MyErrorTracker).trackError(e)))
  4467. * ]
  4468. * }
  4469. * );
  4470. * ```
  4471. *
  4472. * @see {@link NavigationError}
  4473. * @see {@link /api/core/inject inject}
  4474. * @see {@link runInInjectionContext}
  4475. *
  4476. * @returns A set of providers for use with `provideRouter`.
  4477. *
  4478. * @publicApi
  4479. */
  4480. declare function withNavigationErrorHandler(handler: (error: NavigationError) => unknown | RedirectCommand): NavigationErrorHandlerFeature;
  4481. /**
  4482. * A type alias for providers returned by `withComponentInputBinding` for use with `provideRouter`.
  4483. *
  4484. * @see {@link withComponentInputBinding}
  4485. * @see {@link provideRouter}
  4486. *
  4487. * @publicApi
  4488. */
  4489. type ComponentInputBindingFeature = RouterFeature<RouterFeatureKind.ComponentInputBindingFeature>;
  4490. /**
  4491. * A type alias for providers returned by `withViewTransitions` for use with `provideRouter`.
  4492. *
  4493. * @see {@link withViewTransitions}
  4494. * @see {@link provideRouter}
  4495. *
  4496. * @publicApi
  4497. */
  4498. type ViewTransitionsFeature = RouterFeature<RouterFeatureKind.ViewTransitionsFeature>;
  4499. /**
  4500. * Enables binding information from the `Router` state directly to the inputs of the component in
  4501. * `Route` configurations.
  4502. *
  4503. * @usageNotes
  4504. *
  4505. * Basic example of how you can enable the feature:
  4506. * ```ts
  4507. * const appRoutes: Routes = [];
  4508. * bootstrapApplication(AppComponent,
  4509. * {
  4510. * providers: [
  4511. * provideRouter(appRoutes, withComponentInputBinding())
  4512. * ]
  4513. * }
  4514. * );
  4515. * ```
  4516. *
  4517. * The router bindings information from any of the following sources:
  4518. *
  4519. * - query parameters
  4520. * - path and matrix parameters
  4521. * - static route data
  4522. * - data from resolvers
  4523. *
  4524. * Duplicate keys are resolved in the same order from above, from least to greatest,
  4525. * meaning that resolvers have the highest precedence and override any of the other information
  4526. * from the route.
  4527. *
  4528. * Importantly, when an input does not have an item in the route data with a matching key, this
  4529. * input is set to `undefined`. This prevents previous information from being
  4530. * retained if the data got removed from the route (i.e. if a query parameter is removed).
  4531. * Default values can be provided with a resolver on the route to ensure the value is always present
  4532. * or an input and use an input transform in the component.
  4533. *
  4534. * @see {@link /guide/components/inputs#input-transforms Input Transforms}
  4535. * @returns A set of providers for use with `provideRouter`.
  4536. */
  4537. declare function withComponentInputBinding(): ComponentInputBindingFeature;
  4538. /**
  4539. * Enables view transitions in the Router by running the route activation and deactivation inside of
  4540. * `document.startViewTransition`.
  4541. *
  4542. * Note: The View Transitions API is not available in all browsers. If the browser does not support
  4543. * view transitions, the Router will not attempt to start a view transition and continue processing
  4544. * the navigation as usual.
  4545. *
  4546. * @usageNotes
  4547. *
  4548. * Basic example of how you can enable the feature:
  4549. * ```ts
  4550. * const appRoutes: Routes = [];
  4551. * bootstrapApplication(AppComponent,
  4552. * {
  4553. * providers: [
  4554. * provideRouter(appRoutes, withViewTransitions())
  4555. * ]
  4556. * }
  4557. * );
  4558. * ```
  4559. *
  4560. * @returns A set of providers for use with `provideRouter`.
  4561. * @see https://developer.chrome.com/docs/web-platform/view-transitions/
  4562. * @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
  4563. * @developerPreview
  4564. */
  4565. declare function withViewTransitions(options?: ViewTransitionsFeatureOptions): ViewTransitionsFeature;
  4566. /**
  4567. * A type alias that represents all Router features available for use with `provideRouter`.
  4568. * Features can be enabled by adding special functions to the `provideRouter` call.
  4569. * See documentation for each symbol to find corresponding function name. See also `provideRouter`
  4570. * documentation on how to use those functions.
  4571. *
  4572. * @see {@link provideRouter}
  4573. *
  4574. * @publicApi
  4575. */
  4576. type RouterFeatures = PreloadingFeature | DebugTracingFeature | InitialNavigationFeature | InMemoryScrollingFeature | RouterConfigurationFeature | NavigationErrorHandlerFeature | ComponentInputBindingFeature | ViewTransitionsFeature | RouterHashLocationFeature;
  4577. /**
  4578. * The list of features as an enum to uniquely type each feature.
  4579. */
  4580. declare const enum RouterFeatureKind {
  4581. PreloadingFeature = 0,
  4582. DebugTracingFeature = 1,
  4583. EnabledBlockingInitialNavigationFeature = 2,
  4584. DisabledInitialNavigationFeature = 3,
  4585. InMemoryScrollingFeature = 4,
  4586. RouterConfigurationFeature = 5,
  4587. RouterHashLocationFeature = 6,
  4588. NavigationErrorHandlerFeature = 7,
  4589. ComponentInputBindingFeature = 8,
  4590. ViewTransitionsFeature = 9
  4591. }
  4592. /**
  4593. * This component is used internally within the router to be a placeholder when an empty
  4594. * router-outlet is needed. For example, with a config such as:
  4595. *
  4596. * `{path: 'parent', outlet: 'nav', children: [...]}`
  4597. *
  4598. * In order to render, there needs to be a component on this config, which will default
  4599. * to this `EmptyOutletComponent`.
  4600. */
  4601. declare class ɵEmptyOutletComponent {
  4602. static ɵfac: i0.ɵɵFactoryDeclaration<ɵEmptyOutletComponent, never>;
  4603. static ɵcmp: i0.ɵɵComponentDeclaration<ɵEmptyOutletComponent, "ng-component", ["emptyRouterOutlet"], {}, {}, never, never, true, never>;
  4604. }
  4605. declare const ROUTER_PROVIDERS: Provider[];
  4606. /**
  4607. * @description
  4608. *
  4609. * Adds directives and providers for in-app navigation among views defined in an application.
  4610. * Use the Angular `Router` service to declaratively specify application states and manage state
  4611. * transitions.
  4612. *
  4613. * You can import this NgModule multiple times, once for each lazy-loaded bundle.
  4614. * However, only one `Router` service can be active.
  4615. * To ensure this, there are two ways to register routes when importing this module:
  4616. *
  4617. * * The `forRoot()` method creates an `NgModule` that contains all the directives, the given
  4618. * routes, and the `Router` service itself.
  4619. * * The `forChild()` method creates an `NgModule` that contains all the directives and the given
  4620. * routes, but does not include the `Router` service.
  4621. *
  4622. * @see [Routing and Navigation guide](guide/routing/common-router-tasks) for an
  4623. * overview of how the `Router` service should be used.
  4624. *
  4625. * @publicApi
  4626. */
  4627. declare class RouterModule {
  4628. constructor();
  4629. /**
  4630. * Creates and configures a module with all the router providers and directives.
  4631. * Optionally sets up an application listener to perform an initial navigation.
  4632. *
  4633. * When registering the NgModule at the root, import as follows:
  4634. *
  4635. * ```ts
  4636. * @NgModule({
  4637. * imports: [RouterModule.forRoot(ROUTES)]
  4638. * })
  4639. * class MyNgModule {}
  4640. * ```
  4641. *
  4642. * @param routes An array of `Route` objects that define the navigation paths for the application.
  4643. * @param config An `ExtraOptions` configuration object that controls how navigation is performed.
  4644. * @return The new `NgModule`.
  4645. *
  4646. */
  4647. static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterModule>;
  4648. /**
  4649. * Creates a module with all the router directives and a provider registering routes,
  4650. * without creating a new Router service.
  4651. * When registering for submodules and lazy-loaded submodules, create the NgModule as follows:
  4652. *
  4653. * ```ts
  4654. * @NgModule({
  4655. * imports: [RouterModule.forChild(ROUTES)]
  4656. * })
  4657. * class MyNgModule {}
  4658. * ```
  4659. *
  4660. * @param routes An array of `Route` objects that define the navigation paths for the submodule.
  4661. * @return The new NgModule.
  4662. *
  4663. */
  4664. static forChild(routes: Routes): ModuleWithProviders<RouterModule>;
  4665. static ɵfac: i0.ɵɵFactoryDeclaration<RouterModule, never>;
  4666. static ɵmod: i0.ɵɵNgModuleDeclaration<RouterModule, never, [typeof RouterOutlet, typeof RouterLink, typeof RouterLinkActive, typeof ɵEmptyOutletComponent], [typeof RouterOutlet, typeof RouterLink, typeof RouterLinkActive, typeof ɵEmptyOutletComponent]>;
  4667. static ɵinj: i0.ɵɵInjectorDeclaration<RouterModule>;
  4668. }
  4669. /**
  4670. * A DI token for the router initializer that
  4671. * is called after the app is bootstrapped.
  4672. *
  4673. * @publicApi
  4674. */
  4675. declare const ROUTER_INITIALIZER: InjectionToken<(compRef: ComponentRef<any>) => void>;
  4676. /**
  4677. * @description
  4678. *
  4679. * Provides a way to migrate AngularJS applications to Angular.
  4680. *
  4681. * @publicApi
  4682. */
  4683. declare abstract class UrlHandlingStrategy {
  4684. /**
  4685. * Tells the router if this URL should be processed.
  4686. *
  4687. * When it returns true, the router will execute the regular navigation.
  4688. * When it returns false, the router will set the router state to an empty state.
  4689. * As a result, all the active components will be destroyed.
  4690. *
  4691. */
  4692. abstract shouldProcessUrl(url: UrlTree): boolean;
  4693. /**
  4694. * Extracts the part of the URL that should be handled by the router.
  4695. * The rest of the URL will remain untouched.
  4696. */
  4697. abstract extract(url: UrlTree): UrlTree;
  4698. /**
  4699. * Merges the URL fragment with the rest of the URL.
  4700. */
  4701. abstract merge(newUrlPart: UrlTree, rawUrl: UrlTree): UrlTree;
  4702. static ɵfac: i0.ɵɵFactoryDeclaration<UrlHandlingStrategy, never>;
  4703. static ɵprov: i0.ɵɵInjectableDeclaration<UrlHandlingStrategy>;
  4704. }
  4705. /**
  4706. * Maps an array of injectable classes with canMatch functions to an array of equivalent
  4707. * `CanMatchFn` for use in a `Route` definition.
  4708. *
  4709. * Usage {@example router/utils/functional_guards.ts region='CanActivate'}
  4710. *
  4711. * @publicApi
  4712. * @see {@link Route}
  4713. */
  4714. declare function mapToCanMatch(providers: Array<Type<CanMatch>>): CanMatchFn[];
  4715. /**
  4716. * Maps an array of injectable classes with canActivate functions to an array of equivalent
  4717. * `CanActivateFn` for use in a `Route` definition.
  4718. *
  4719. * Usage {@example router/utils/functional_guards.ts region='CanActivate'}
  4720. *
  4721. * @publicApi
  4722. * @see {@link Route}
  4723. */
  4724. declare function mapToCanActivate(providers: Array<Type<CanActivate>>): CanActivateFn[];
  4725. /**
  4726. * Maps an array of injectable classes with canActivateChild functions to an array of equivalent
  4727. * `CanActivateChildFn` for use in a `Route` definition.
  4728. *
  4729. * Usage {@example router/utils/functional_guards.ts region='CanActivate'}
  4730. *
  4731. * @publicApi
  4732. * @see {@link Route}
  4733. */
  4734. declare function mapToCanActivateChild(providers: Array<Type<CanActivateChild>>): CanActivateChildFn[];
  4735. /**
  4736. * Maps an array of injectable classes with canDeactivate functions to an array of equivalent
  4737. * `CanDeactivateFn` for use in a `Route` definition.
  4738. *
  4739. * Usage {@example router/utils/functional_guards.ts region='CanActivate'}
  4740. *
  4741. * @publicApi
  4742. * @see {@link Route}
  4743. */
  4744. declare function mapToCanDeactivate<T = unknown>(providers: Array<Type<CanDeactivate<T>>>): CanDeactivateFn<T>[];
  4745. /**
  4746. * Maps an injectable class with a resolve function to an equivalent `ResolveFn`
  4747. * for use in a `Route` definition.
  4748. *
  4749. * Usage {@example router/utils/functional_guards.ts region='Resolve'}
  4750. *
  4751. * @publicApi
  4752. * @see {@link Route}
  4753. */
  4754. declare function mapToResolve<T>(provider: Type<Resolve<T>>): ResolveFn<T>;
  4755. /**
  4756. * @module
  4757. * @description
  4758. * Entry point for all public APIs of the router package.
  4759. */
  4760. /**
  4761. * @publicApi
  4762. */
  4763. declare const VERSION: Version;
  4764. /**
  4765. * Performs the given action once the router finishes its next/current navigation.
  4766. *
  4767. * The navigation is considered complete under the following conditions:
  4768. * - `NavigationCancel` event emits and the code is not `NavigationCancellationCode.Redirect` or
  4769. * `NavigationCancellationCode.SupersededByNewNavigation`. In these cases, the
  4770. * redirecting/superseding navigation must finish.
  4771. * - `NavigationError`, `NavigationEnd`, or `NavigationSkipped` event emits
  4772. */
  4773. declare function afterNextNavigation(router: {
  4774. events: Observable<Event>;
  4775. }, action: () => void): void;
  4776. export { ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, BaseRouteReuseStrategy, type CanActivate, type CanActivateChild, type CanActivateChildFn, type CanActivateFn, type CanDeactivate, type CanDeactivateFn, type CanLoad, type CanLoadFn, type CanMatch, type CanMatchFn, ChildActivationEnd, ChildActivationStart, ChildrenOutletContexts, type ComponentInputBindingFeature, type Data, type DebugTracingFeature, type DefaultExport, DefaultTitleStrategy, DefaultUrlSerializer, type DeprecatedGuard, type DetachedRouteHandle, type DisabledInitialNavigationFeature, type EnabledBlockingInitialNavigationFeature, type Event, EventType, type ExtraOptions, type GuardResult, GuardsCheckEnd, GuardsCheckStart, type InMemoryScrollingFeature, type InMemoryScrollingOptions, type InitialNavigation, type InitialNavigationFeature, type IsActiveMatchOptions, type LoadChildren, type LoadChildrenCallback, type MaybeAsync, type Navigation, type NavigationBehaviorOptions, NavigationCancel, NavigationCancellationCode, NavigationEnd, NavigationError, type NavigationErrorHandlerFeature, type NavigationExtras, NavigationSkipped, NavigationSkippedCode, NavigationStart, NoPreloading, type OnSameUrlNavigation, OutletContext, PRIMARY_OUTLET, type ParamMap, type Params, PreloadAllModules, type PreloadingFeature, PreloadingStrategy, type QueryParamsHandling, ROUTER_CONFIGURATION, ROUTER_INITIALIZER, ROUTER_OUTLET_DATA, ROUTES, RedirectCommand, type RedirectFunction, type Resolve, type ResolveData, ResolveEnd, type ResolveFn, ResolveStart, type Route, RouteConfigLoadEnd, RouteConfigLoadStart, RouteReuseStrategy, Router, type RouterConfigOptions, type RouterConfigurationFeature, RouterEvent, type RouterFeature, type RouterFeatures, type RouterHashLocationFeature, RouterLink, RouterLinkActive, RouterLink as RouterLinkWithHref, RouterModule, RouterOutlet, type RouterOutletContract, RouterPreloader, RouterState, RouterStateSnapshot, type Routes, RoutesRecognized, type RunGuardsAndResolvers, Scroll, TitleStrategy, type UrlCreationOptions, UrlHandlingStrategy, type UrlMatchResult, type UrlMatcher, UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree, VERSION, type ViewTransitionInfo, type ViewTransitionsFeature, type ViewTransitionsFeatureOptions, convertToParamMap, createUrlTreeFromSnapshot, defaultUrlMatcher, mapToCanActivate, mapToCanActivateChild, mapToCanDeactivate, mapToCanMatch, mapToResolve, provideRouter, provideRoutes, withComponentInputBinding, withDebugTracing, withDisabledInitialNavigation, withEnabledBlockingInitialNavigation, withHashLocation, withInMemoryScrolling, withNavigationErrorHandler, withPreloading, withRouterConfig, withViewTransitions, ɵEmptyOutletComponent, ROUTER_PROVIDERS as ɵROUTER_PROVIDERS, type RestoredState as ɵRestoredState, afterNextNavigation as ɵafterNextNavigation, loadChildren as ɵloadChildren };