router_module.d-Bx9ArA6K.d.ts 137 KB

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