UNPKG

@angular/router

Version:
1,452 lines (1,393 loc) 173 kB
/** * @license Angular v18.2.8 * (c) 2010-2024 Google LLC. https://angular.io/ * License: MIT */ import { AfterContentInit } from '@angular/core'; import { ChangeDetectorRef } from '@angular/core'; import { Compiler } from '@angular/core'; import { ComponentRef } from '@angular/core'; import { ElementRef } from '@angular/core'; import { EnvironmentInjector } from '@angular/core'; import { EnvironmentProviders } from '@angular/core'; import { EventEmitter } from '@angular/core'; import * as i0 from '@angular/core'; import { InjectionToken } from '@angular/core'; import { Injector } from '@angular/core'; import { LocationStrategy } from '@angular/common'; import { ModuleWithProviders } from '@angular/core'; import { NgModuleFactory } from '@angular/core'; import { Observable } from 'rxjs'; import { OnChanges } from '@angular/core'; import { OnDestroy } from '@angular/core'; import { OnInit } from '@angular/core'; import { Provider } from '@angular/core'; import { ProviderToken } from '@angular/core'; import { QueryList } from '@angular/core'; import { Renderer2 } from '@angular/core'; import { RouterState as RouterState_2 } from '@angular/router'; import { SimpleChanges } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { Type } from '@angular/core'; import { Version } from '@angular/core'; /** * Provides access to information about a route associated with a component * that is loaded in an outlet. * Use to traverse the `RouterState` tree and extract information from nodes. * * The following example shows how to construct a component using information from a * currently activated route. * * Note: the observables in this class only emit when the current and previous values differ based * on shallow equality. For example, changing deeply nested properties in resolved `data` will not * cause the `ActivatedRoute.data` `Observable` to emit a new value. * * {@example router/activated-route/module.ts region="activated-route" * header="activated-route.component.ts"} * * @see [Getting route information](guide/routing/common-router-tasks#getting-route-information) * * @publicApi */ export declare class ActivatedRoute { /** The outlet name of the route, a constant. */ outlet: string; /** The component of the route, a constant. */ component: Type<any> | null; /** The current snapshot of this route */ snapshot: ActivatedRouteSnapshot; /** An Observable of the resolved route title */ readonly title: Observable<string | undefined>; /** An observable of the URL segments matched by this route. */ url: Observable<UrlSegment[]>; /** An observable of the matrix parameters scoped to this route. */ params: Observable<Params>; /** An observable of the query parameters shared by all the routes. */ queryParams: Observable<Params>; /** An observable of the URL fragment shared by all the routes. */ fragment: Observable<string | null>; /** An observable of the static and resolved data of this route. */ data: Observable<Data>; /** The configuration used to match this route. */ get routeConfig(): Route | null; /** The root of the router state. */ get root(): ActivatedRoute; /** The parent of this route in the router state tree. */ get parent(): ActivatedRoute | null; /** The first child of this route in the router state tree. */ get firstChild(): ActivatedRoute | null; /** The children of this route in the router state tree. */ get children(): ActivatedRoute[]; /** The path from the root of the router state tree to this route. */ get pathFromRoot(): ActivatedRoute[]; /** * An Observable that contains a map of the required and optional parameters * specific to the route. * The map supports retrieving single and multiple values from the same parameter. */ get paramMap(): Observable<ParamMap>; /** * An Observable that contains a map of the query parameters available to all routes. * The map supports retrieving single and multiple values from the query parameter. */ get queryParamMap(): Observable<ParamMap>; toString(): string; } /** * @description * * Contains the information about a route associated with a component loaded in an * outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to * traverse the router state tree. * * The following example initializes a component with route information extracted * from the snapshot of the root node at the time of creation. * * ``` * @Component({templateUrl:'./my-component.html'}) * class MyComponent { * constructor(route: ActivatedRoute) { * const id: string = route.snapshot.params.id; * const url: string = route.snapshot.url.join(''); * const user = route.snapshot.data.user; * } * } * ``` * * @publicApi */ export declare class ActivatedRouteSnapshot { /** The URL segments matched by this route */ url: UrlSegment[]; /** * The matrix parameters scoped to this route. * * You can compute all params (or data) in the router state or to get params outside * of an activated component by traversing the `RouterState` tree as in the following * example: * ``` * collectRouteParams(router: Router) { * let params = {}; * let stack: ActivatedRouteSnapshot[] = [router.routerState.snapshot.root]; * while (stack.length > 0) { * const route = stack.pop()!; * params = {...params, ...route.params}; * stack.push(...route.children); * } * return params; * } * ``` */ params: Params; /** The query parameters shared by all the routes */ queryParams: Params; /** The URL fragment shared by all the routes */ fragment: string | null; /** The static and resolved data of this route */ data: Data; /** The outlet name of the route */ outlet: string; /** The component of the route */ component: Type<any> | null; /** The configuration used to match this route **/ readonly routeConfig: Route | null; /** The resolved route title */ get title(): string | undefined; /** The root of the router state */ get root(): ActivatedRouteSnapshot; /** The parent of this route in the router state tree */ get parent(): ActivatedRouteSnapshot | null; /** The first child of this route in the router state tree */ get firstChild(): ActivatedRouteSnapshot | null; /** The children of this route in the router state tree */ get children(): ActivatedRouteSnapshot[]; /** The path from the root of the router state tree to this route */ get pathFromRoot(): ActivatedRouteSnapshot[]; get paramMap(): ParamMap; get queryParamMap(): ParamMap; toString(): string; } /** * An event triggered at the end of the activation part * of the Resolve phase of routing. * @see {@link ActivationStart} * @see {@link ResolveStart} * * @publicApi */ export declare class ActivationEnd { /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot; readonly type = EventType.ActivationEnd; constructor( /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot); toString(): string; } /** * An event triggered at the start of the activation part * of the Resolve phase of routing. * @see {@link ActivationEnd} * @see {@link ResolveStart} * * @publicApi */ export declare class ActivationStart { /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot; readonly type = EventType.ActivationStart; constructor( /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot); toString(): string; } /** * @description * * This base route reuse strategy only reuses routes when the matched router configs are * identical. This prevents components from being destroyed and recreated * when just the route parameters, query parameters or fragment change * (that is, the existing component is _reused_). * * This strategy does not store any routes for later reuse. * * Angular uses this strategy by default. * * * It can be used as a base class for custom route reuse strategies, i.e. you can create your own * class that extends the `BaseRouteReuseStrategy` one. * @publicApi */ export declare abstract class BaseRouteReuseStrategy implements RouteReuseStrategy { /** * Whether the given route should detach for later reuse. * Always returns false for `BaseRouteReuseStrategy`. * */ shouldDetach(route: ActivatedRouteSnapshot): boolean; /** * A no-op; the route is never stored since this strategy never detaches routes for later re-use. */ store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void; /** Returns `false`, meaning the route (and its subtree) is never reattached */ shouldAttach(route: ActivatedRouteSnapshot): boolean; /** Returns `null` because this strategy does not store routes for later re-use. */ retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null; /** * Determines if a route should be reused. * This strategy returns `true` when the future route config and current route config are * identical. */ shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean; } /** * @description * * Interface that a class can implement to be a guard deciding if a route can be activated. * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation * is cancelled and a new navigation begins to the `UrlTree` returned from the guard. * * The following example implements a `CanActivate` function that checks whether the * current user has permission to activate the requested route. * * ``` * class UserToken {} * class Permissions { * canActivate(): boolean { * return true; * } * } * * @Injectable() * class CanActivateTeam implements CanActivate { * constructor(private permissions: Permissions, private currentUser: UserToken) {} * * canActivate( * route: ActivatedRouteSnapshot, * state: RouterStateSnapshot * ): MaybeAsync<GuardResult> { * return this.permissions.canActivate(this.currentUser, route.params.id); * } * } * ``` * * Here, the defined guard function is provided as part of the `Route` object * in the router configuration: * * ``` * @NgModule({ * imports: [ * RouterModule.forRoot([ * { * path: 'team/:id', * component: TeamComponent, * canActivate: [CanActivateTeam] * } * ]) * ], * providers: [CanActivateTeam, UserToken, Permissions] * }) * class AppModule {} * ``` * * @publicApi */ export declare interface CanActivate { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): MaybeAsync<GuardResult>; } /** * @description * * Interface that a class can implement to be a guard deciding if a child route can be activated. * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, current navigation * is cancelled and a new navigation begins to the `UrlTree` returned from the guard. * * The following example implements a `CanActivateChild` function that checks whether the * current user has permission to activate the requested child route. * * ``` * class UserToken {} * class Permissions { * canActivate(user: UserToken, id: string): boolean { * return true; * } * } * * @Injectable() * class CanActivateTeam implements CanActivateChild { * constructor(private permissions: Permissions, private currentUser: UserToken) {} * * canActivateChild( * route: ActivatedRouteSnapshot, * state: RouterStateSnapshot * ): MaybeAsync<GuardResult> { * return this.permissions.canActivate(this.currentUser, route.params.id); * } * } * ``` * * Here, the defined guard function is provided as part of the `Route` object * in the router configuration: * * ``` * @NgModule({ * imports: [ * RouterModule.forRoot([ * { * path: 'root', * canActivateChild: [CanActivateTeam], * children: [ * { * path: 'team/:id', * component: TeamComponent * } * ] * } * ]) * ], * providers: [CanActivateTeam, UserToken, Permissions] * }) * class AppModule {} * ``` * * @publicApi */ export declare interface CanActivateChild { canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): MaybeAsync<GuardResult>; } /** * The signature of a function used as a `canActivateChild` guard on a `Route`. * * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation * is cancelled and a new navigation begins to the `UrlTree` returned from the guard. * * The following example implements a `canActivate` function that checks whether the * current user has permission to activate the requested route. * * {@example router/route_functional_guards.ts region="CanActivateChildFn"} * * @publicApi * @see {@link Route} */ export declare type CanActivateChildFn = (childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot) => MaybeAsync<GuardResult>; /** * The signature of a function used as a `canActivate` guard on a `Route`. * * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation * is cancelled and a new navigation begins to the `UrlTree` returned from the guard. * * The following example implements and uses a `CanActivateFn` that checks whether the * current user has permission to activate the requested route. * * ```ts * @Injectable() * class UserToken {} * * @Injectable() * class PermissionsService { * canActivate(currentUser: UserToken, userId: string): boolean { * return true; * } * canMatch(currentUser: UserToken): boolean { * return true; * } * } * * const canActivateTeam: CanActivateFn = ( * route: ActivatedRouteSnapshot, * state: RouterStateSnapshot, * ) => { * return inject(PermissionsService).canActivate(inject(UserToken), route.params['id']); * }; * ``` * * Here, the defined guard function is provided as part of the `Route` object * in the router configuration: * * ```ts * bootstrapApplication(App, { * providers: [ * provideRouter([ * { * path: 'team/:id', * component: TeamComponent, * canActivate: [canActivateTeam], * }, * ]), * ], * }); * ``` * * @publicApi * @see {@link Route} */ export declare type CanActivateFn = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => MaybeAsync<GuardResult>; /** * @description * * Interface that a class can implement to be a guard deciding if a route can be deactivated. * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, current navigation * is cancelled and a new navigation begins to the `UrlTree` returned from the guard. * * The following example implements a `CanDeactivate` function that checks whether the * current user has permission to deactivate the requested route. * * ``` * class UserToken {} * class Permissions { * canDeactivate(user: UserToken, id: string): boolean { * return true; * } * } * ``` * * Here, the defined guard function is provided as part of the `Route` object * in the router configuration: * * ``` * * @Injectable() * class CanDeactivateTeam implements CanDeactivate<TeamComponent> { * constructor(private permissions: Permissions, private currentUser: UserToken) {} * * canDeactivate( * component: TeamComponent, * currentRoute: ActivatedRouteSnapshot, * currentState: RouterStateSnapshot, * nextState: RouterStateSnapshot * ): MaybeAsync<GuardResult> { * return this.permissions.canDeactivate(this.currentUser, route.params.id); * } * } * * @NgModule({ * imports: [ * RouterModule.forRoot([ * { * path: 'team/:id', * component: TeamComponent, * canDeactivate: [CanDeactivateTeam] * } * ]) * ], * providers: [CanDeactivateTeam, UserToken, Permissions] * }) * class AppModule {} * ``` * * @publicApi */ export declare interface CanDeactivate<T> { canDeactivate(component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot): MaybeAsync<GuardResult>; } /** * The signature of a function used as a `canDeactivate` guard on a `Route`. * * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, the current navigation * is cancelled and a new navigation begins to the `UrlTree` returned from the guard. * * The following example implements and uses a `CanDeactivateFn` that checks whether the * user component has unsaved changes before navigating away from the route. * * {@example router/route_functional_guards.ts region="CanDeactivateFn"} * * @publicApi * @see {@link Route} */ export declare type CanDeactivateFn<T> = (component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot) => MaybeAsync<GuardResult>; /** * @description * * Interface that a class can implement to be a guard deciding if children can be loaded. * If all guards return `true`, navigation continues. If any guard returns `false`, * navigation is cancelled. If any guard returns a `UrlTree`, current navigation * is cancelled and a new navigation starts to the `UrlTree` returned from the guard. * * The following example implements a `CanLoad` function that decides whether the * current user has permission to load requested child routes. * * * ``` * class UserToken {} * class Permissions { * canLoadChildren(user: UserToken, id: string, segments: UrlSegment[]): boolean { * return true; * } * } * * @Injectable() * class CanLoadTeamSection implements CanLoad { * constructor(private permissions: Permissions, private currentUser: UserToken) {} * * canLoad(route: Route, segments: UrlSegment[]): Observable<boolean>|Promise<boolean>|boolean { * return this.permissions.canLoadChildren(this.currentUser, route, segments); * } * } * ``` * * Here, the defined guard function is provided as part of the `Route` object * in the router configuration: * * ``` * * @NgModule({ * imports: [ * RouterModule.forRoot([ * { * path: 'team/:id', * component: TeamComponent, * loadChildren: () => import('./team').then(mod => mod.TeamModule), * canLoad: [CanLoadTeamSection] * } * ]) * ], * providers: [CanLoadTeamSection, UserToken, Permissions] * }) * class AppModule {} * ``` * * @publicApi * @deprecated Use {@link CanMatch} instead */ export declare interface CanLoad { canLoad(route: Route, segments: UrlSegment[]): MaybeAsync<GuardResult>; } /** * The signature of a function used as a `canLoad` guard on a `Route`. * * @publicApi * @see {@link CanLoad} * @see {@link Route} * @see {@link CanMatch} * @deprecated Use `Route.canMatch` and `CanMatchFn` instead */ export declare type CanLoadFn = (route: Route, segments: UrlSegment[]) => MaybeAsync<GuardResult>; /** * @description * * Interface that a class can implement to be a guard deciding if a `Route` can be matched. * If all guards return `true`, navigation continues and the `Router` will use the `Route` during * activation. If any guard returns `false`, the `Route` is skipped for matching and other `Route` * configurations are processed instead. * * The following example implements a `CanMatch` function that decides whether the * current user has permission to access the users page. * * * ``` * class UserToken {} * class Permissions { * canAccess(user: UserToken, route: Route, segments: UrlSegment[]): boolean { * return true; * } * } * * @Injectable() * class CanMatchTeamSection implements CanMatch { * constructor(private permissions: Permissions, private currentUser: UserToken) {} * * canMatch(route: Route, segments: UrlSegment[]): Observable<boolean>|Promise<boolean>|boolean { * return this.permissions.canAccess(this.currentUser, route, segments); * } * } * ``` * * Here, the defined guard function is provided as part of the `Route` object * in the router configuration: * * ``` * * @NgModule({ * imports: [ * RouterModule.forRoot([ * { * path: 'team/:id', * component: TeamComponent, * loadChildren: () => import('./team').then(mod => mod.TeamModule), * canMatch: [CanMatchTeamSection] * }, * { * path: '**', * component: NotFoundComponent * } * ]) * ], * providers: [CanMatchTeamSection, UserToken, Permissions] * }) * class AppModule {} * ``` * * If the `CanMatchTeamSection` were to return `false`, the router would continue navigating to the * `team/:id` URL, but would load the `NotFoundComponent` because the `Route` for `'team/:id'` * could not be used for a URL match but the catch-all `**` `Route` did instead. * * @publicApi */ export declare interface CanMatch { canMatch(route: Route, segments: UrlSegment[]): MaybeAsync<GuardResult>; } /** * The signature of a function used as a `canMatch` guard on a `Route`. * * If all guards return `true`, navigation continues and the `Router` will use the `Route` during * activation. If any guard returns `false`, the `Route` is skipped for matching and other `Route` * configurations are processed instead. * * The following example implements and uses a `CanMatchFn` that checks whether the * current user has permission to access the team page. * * {@example router/route_functional_guards.ts region="CanMatchFn"} * * @publicApi * @see {@link Route} */ export declare type CanMatchFn = (route: Route, segments: UrlSegment[]) => MaybeAsync<GuardResult>; /** * An event triggered at the end of the child-activation part * of the Resolve phase of routing. * @see {@link ChildActivationStart} * @see {@link ResolveStart} * @publicApi */ export declare class ChildActivationEnd { /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot; readonly type = EventType.ChildActivationEnd; constructor( /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot); toString(): string; } /** * An event triggered at the start of the child-activation * part of the Resolve phase of routing. * @see {@link ChildActivationEnd} * @see {@link ResolveStart} * * @publicApi */ export declare class ChildActivationStart { /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot; readonly type = EventType.ChildActivationStart; constructor( /** @docsNotRequired */ snapshot: ActivatedRouteSnapshot); toString(): string; } /** * Store contextual information about the children (= nested) `RouterOutlet` * * @publicApi */ export declare class ChildrenOutletContexts { private rootInjector; private contexts; /** @nodoc */ constructor(rootInjector: EnvironmentInjector); /** Called when a `RouterOutlet` directive is instantiated */ onChildOutletCreated(childName: string, outlet: RouterOutletContract): void; /** * Called when a `RouterOutlet` directive is destroyed. * We need to keep the context as the outlet could be destroyed inside a NgIf and might be * re-created later. */ onChildOutletDestroyed(childName: string): void; /** * Called when the corresponding route is deactivated during navigation. * Because the component get destroyed, all children outlet are destroyed. */ onOutletDeactivated(): Map<string, OutletContext>; onOutletReAttached(contexts: Map<string, OutletContext>): void; getOrCreateContext(childName: string): OutletContext; getContext(childName: string): OutletContext | null; static ɵfac: i0.ɵɵFactoryDeclaration<ChildrenOutletContexts, never>; static ɵprov: i0.ɵɵInjectableDeclaration<ChildrenOutletContexts>; } /** * A type alias for providers returned by `withComponentInputBinding` for use with `provideRouter`. * * @see {@link withComponentInputBinding} * @see {@link provideRouter} * * @publicApi */ declare type ComponentInputBindingFeature = RouterFeature<RouterFeatureKind.ComponentInputBindingFeature>; /** * Converts a `Params` instance to a `ParamMap`. * @param params The instance to convert. * @returns The new map instance. * * @publicApi */ export declare function convertToParamMap(params: Params): ParamMap; /** * Creates a `UrlTree` relative to an `ActivatedRouteSnapshot`. * * @publicApi * * * @param relativeTo The `ActivatedRouteSnapshot` to apply the commands to * @param commands An array of URL fragments with which to construct the new URL tree. * If the path is static, can be the literal URL string. For a dynamic path, pass an array of path * segments, followed by the parameters for each segment. * The fragments are applied to the one provided in the `relativeTo` parameter. * @param queryParams The query parameters for the `UrlTree`. `null` if the `UrlTree` does not have * any query parameters. * @param fragment The fragment for the `UrlTree`. `null` if the `UrlTree` does not have a fragment. * * @usageNotes * * ``` * // create /team/33/user/11 * createUrlTreeFromSnapshot(snapshot, ['/team', 33, 'user', 11]); * * // create /team/33;expand=true/user/11 * createUrlTreeFromSnapshot(snapshot, ['/team', 33, {expand: true}, 'user', 11]); * * // you can collapse static segments like this (this works only with the first passed-in value): * createUrlTreeFromSnapshot(snapshot, ['/team/33/user', userId]); * * // If the first segment can contain slashes, and you do not want the router to split it, * // you can do the following: * createUrlTreeFromSnapshot(snapshot, [{segmentPath: '/one/two'}]); * * // create /team/33/(user/11//right:chat) * createUrlTreeFromSnapshot(snapshot, ['/team', 33, {outlets: {primary: 'user/11', right: * 'chat'}}], null, null); * * // remove the right secondary node * createUrlTreeFromSnapshot(snapshot, ['/team', 33, {outlets: {primary: 'user/11', right: null}}]); * * // For the examples below, assume the current URL is for the `/team/33/user/11` and the * `ActivatedRouteSnapshot` points to `user/11`: * * // navigate to /team/33/user/11/details * createUrlTreeFromSnapshot(snapshot, ['details']); * * // navigate to /team/33/user/22 * createUrlTreeFromSnapshot(snapshot, ['../22']); * * // navigate to /team/44/user/22 * createUrlTreeFromSnapshot(snapshot, ['../../team/44/user/22']); * ``` */ export declare function createUrlTreeFromSnapshot(relativeTo: ActivatedRouteSnapshot, commands: any[], queryParams?: Params | null, fragment?: string | null): UrlTree; /** * * Represents static data associated with a particular route. * * @see {@link Route#data} * * @publicApi */ export declare type Data = { [key: string | symbol]: any; }; /** * A type alias for providers returned by `withDebugTracing` for use with `provideRouter`. * * @see {@link withDebugTracing} * @see {@link provideRouter} * * @publicApi */ export declare type DebugTracingFeature = RouterFeature<RouterFeatureKind.DebugTracingFeature>; /** * An ES Module object with a default export of the given type. * * @see {@link Route#loadComponent} * @see {@link LoadChildrenCallback} * * @publicApi */ export declare interface DefaultExport<T> { /** * Default exports are bound under the name `"default"`, per the ES Module spec: * https://tc39.es/ecma262/#table-export-forms-mapping-to-exportentry-records */ default: T; } /** * The default `TitleStrategy` used by the router that updates the title using the `Title` service. */ export declare class DefaultTitleStrategy extends TitleStrategy { readonly title: Title; constructor(title: Title); /** * Sets the title of the browser to the given value. * * @param title The `pageTitle` from the deepest primary route. */ updateTitle(snapshot: RouterStateSnapshot): void; static ɵfac: i0.ɵɵFactoryDeclaration<DefaultTitleStrategy, never>; static ɵprov: i0.ɵɵInjectableDeclaration<DefaultTitleStrategy>; } /** * Matches the route configuration (`route`) against the actual URL (`segments`). * * When no matcher is defined on a `Route`, this is the matcher used by the Router by default. * * @param segments The remaining unmatched segments in the current navigation * @param segmentGroup The current segment group being matched * @param route The `Route` to match against. * * @see {@link UrlMatchResult} * @see {@link Route} * * @returns The resulting match information or `null` if the `route` should not match. * @publicApi */ export declare function defaultUrlMatcher(segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult | null; /** * @description * * A default implementation of the `UrlSerializer`. * * Example URLs: * * ``` * /inbox/33(popup:compose) * /inbox/33;open=true/messages/44 * ``` * * DefaultUrlSerializer uses parentheses to serialize secondary segments (e.g., popup:compose), the * colon syntax to specify the outlet, and the ';parameter=value' syntax (e.g., open=true) to * specify route specific parameters. * * @publicApi */ export declare class DefaultUrlSerializer implements UrlSerializer { /** Parses a url into a `UrlTree` */ parse(url: string): UrlTree; /** Converts a `UrlTree` into a url */ serialize(tree: UrlTree): string; } /** * The `InjectionToken` and `@Injectable` classes for guards and resolvers are deprecated in favor * of plain JavaScript functions instead.. Dependency injection can still be achieved using the * [`inject`](api/core/inject) function from `@angular/core` and an injectable class can be used as * a functional guard using [`inject`](api/core/inject): `canActivate: [() => * inject(myGuard).canActivate()]`. * * @deprecated * @see {@link CanMatchFn} * @see {@link CanLoadFn} * @see {@link CanActivateFn} * @see {@link CanActivateChildFn} * @see {@link CanDeactivateFn} * @see {@link ResolveFn} * @see {@link core/inject} * @publicApi */ export declare type DeprecatedGuard = ProviderToken<any> | any; /** * @description * * Represents the detached route tree. * * This is an opaque value the router will give to a custom route reuse strategy * to store and retrieve later on. * * @publicApi */ export declare type DetachedRouteHandle = {}; /** * A type alias for providers returned by `withDisabledInitialNavigation` for use with * `provideRouter`. * * @see {@link withDisabledInitialNavigation} * @see {@link provideRouter} * * @publicApi */ export declare type DisabledInitialNavigationFeature = RouterFeature<RouterFeatureKind.DisabledInitialNavigationFeature>; /** * A type alias for providers returned by `withEnabledBlockingInitialNavigation` for use with * `provideRouter`. * * @see {@link withEnabledBlockingInitialNavigation} * @see {@link provideRouter} * * @publicApi */ export declare type EnabledBlockingInitialNavigationFeature = RouterFeature<RouterFeatureKind.EnabledBlockingInitialNavigationFeature>; /** * Router events that allow you to track the lifecycle of the router. * * The events occur in the following sequence: * * * [NavigationStart](api/router/NavigationStart): Navigation starts. * * [RouteConfigLoadStart](api/router/RouteConfigLoadStart): Before * the router [lazy loads](guide/routing/common-router-tasks#lazy-loading) a route configuration. * * [RouteConfigLoadEnd](api/router/RouteConfigLoadEnd): After a route has been lazy loaded. * * [RoutesRecognized](api/router/RoutesRecognized): When the router parses the URL * and the routes are recognized. * * [GuardsCheckStart](api/router/GuardsCheckStart): When the router begins the *guards* * phase of routing. * * [ChildActivationStart](api/router/ChildActivationStart): When the router * begins activating a route's children. * * [ActivationStart](api/router/ActivationStart): When the router begins activating a route. * * [GuardsCheckEnd](api/router/GuardsCheckEnd): When the router finishes the *guards* * phase of routing successfully. * * [ResolveStart](api/router/ResolveStart): When the router begins the *resolve* * phase of routing. * * [ResolveEnd](api/router/ResolveEnd): When the router finishes the *resolve* * phase of routing successfully. * * [ChildActivationEnd](api/router/ChildActivationEnd): When the router finishes * activating a route's children. * * [ActivationEnd](api/router/ActivationEnd): When the router finishes activating a route. * * [NavigationEnd](api/router/NavigationEnd): When navigation ends successfully. * * [NavigationCancel](api/router/NavigationCancel): When navigation is canceled. * * [NavigationError](api/router/NavigationError): When navigation fails * due to an unexpected error. * * [Scroll](api/router/Scroll): When the user scrolls. * * @publicApi */ declare type Event_2 = NavigationStart | NavigationEnd | NavigationCancel | NavigationError | RoutesRecognized | GuardsCheckStart | GuardsCheckEnd | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivationStart | ChildActivationEnd | ActivationStart | ActivationEnd | Scroll | ResolveStart | ResolveEnd | NavigationSkipped; export { Event_2 as Event } /** * Identifies the type of a router event. * * @publicApi */ export declare enum EventType { NavigationStart = 0, NavigationEnd = 1, NavigationCancel = 2, NavigationError = 3, RoutesRecognized = 4, ResolveStart = 5, ResolveEnd = 6, GuardsCheckStart = 7, GuardsCheckEnd = 8, RouteConfigLoadStart = 9, RouteConfigLoadEnd = 10, ChildActivationStart = 11, ChildActivationEnd = 12, ActivationStart = 13, ActivationEnd = 14, Scroll = 15, NavigationSkipped = 16 } /** * A set of configuration options for a router module, provided in the * `forRoot()` method. * * @see {@link forRoot()} * * * @publicApi */ export declare interface ExtraOptions extends InMemoryScrollingOptions, RouterConfigOptions { /** * When true, log all internal navigation events to the console. * Use for debugging. */ enableTracing?: boolean; /** * When true, enable the location strategy that uses the URL fragment * instead of the history API. */ useHash?: boolean; /** * One of `enabled`, `enabledBlocking`, `enabledNonBlocking` or `disabled`. * When set to `enabled` or `enabledBlocking`, the initial navigation starts before the root * component is created. The bootstrap is blocked until the initial navigation is complete. This * value should be set in case you use [server-side rendering](guide/ssr), but do not enable * [hydration](guide/hydration) for your application. When set to `enabledNonBlocking`, * the initial navigation starts after the root component has been created. * The bootstrap is not blocked on the completion of the initial navigation. When set to * `disabled`, the initial navigation is not performed. The location listener is set up before the * root component gets created. Use if there is a reason to have more control over when the router * starts its initial navigation due to some complex initialization logic. */ initialNavigation?: InitialNavigation; /** * When true, enables binding information from the `Router` state directly to the inputs of the * component in `Route` configurations. */ bindToComponentInputs?: boolean; /** * When true, enables view transitions in the Router by running the route activation and * deactivation inside of `document.startViewTransition`. * * @see https://developer.chrome.com/docs/web-platform/view-transitions/ * @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API * @experimental */ enableViewTransitions?: boolean; /** * A custom error handler for failed navigations. * If the handler returns a value, the navigation Promise is resolved with this value. * If the handler throws an exception, the navigation Promise is rejected with the exception. * * @deprecated Subscribe to the `Router` events and watch for `NavigationError` instead. * If the ErrorHandler is used to prevent unhandled promise rejections when navigation * errors occur, use the `resolveNavigationPromiseOnError` option instead. * * @see RouterConfigOptions */ errorHandler?: (error: any) => any; /** * Configures a preloading strategy. * One of `PreloadAllModules` or `NoPreloading` (the default). */ preloadingStrategy?: any; /** * Configures the scroll offset the router will use when scrolling to an element. * * When given a tuple with x and y position value, * the router uses that offset each time it scrolls. * When given a function, the router invokes the function every time * it restores scroll position. */ scrollOffset?: [number, number] | (() => [number, number]); } /** * The supported types that can be returned from a `Router` guard. * * @see [Routing guide](guide/routing/common-router-tasks#preventing-unauthorized-access) * @publicApi */ export declare type GuardResult = boolean | UrlTree | RedirectCommand; /** * An event triggered at the end of the Guard phase of routing. * * @see {@link GuardsCheckStart} * * @publicApi */ export declare class GuardsCheckEnd extends RouterEvent { /** @docsNotRequired */ urlAfterRedirects: string; /** @docsNotRequired */ state: RouterStateSnapshot; /** @docsNotRequired */ shouldActivate: boolean; readonly type = EventType.GuardsCheckEnd; constructor( /** @docsNotRequired */ id: number, /** @docsNotRequired */ url: string, /** @docsNotRequired */ urlAfterRedirects: string, /** @docsNotRequired */ state: RouterStateSnapshot, /** @docsNotRequired */ shouldActivate: boolean); toString(): string; } /** * An event triggered at the start of the Guard phase of routing. * * @see {@link GuardsCheckEnd} * * @publicApi */ export declare class GuardsCheckStart extends RouterEvent { /** @docsNotRequired */ urlAfterRedirects: string; /** @docsNotRequired */ state: RouterStateSnapshot; readonly type = EventType.GuardsCheckStart; constructor( /** @docsNotRequired */ id: number, /** @docsNotRequired */ url: string, /** @docsNotRequired */ urlAfterRedirects: string, /** @docsNotRequired */ state: RouterStateSnapshot); toString(): string; } declare namespace i1 { export { RouterOutletContract, RouterOutlet, INPUT_BINDER, RoutedComponentInputBinder } } declare namespace i2 { export { RouterLink, RouterLink as RouterLinkWithHref } } declare namespace i3 { export { RouterLinkActive } } declare namespace i4 { export { standardizeConfig, ɵEmptyOutletComponent as EmptyOutletComponent, ɵEmptyOutletComponent } } /** * Allowed values in an `ExtraOptions` object that configure * when the router performs the initial navigation operation. * * * 'enabledNonBlocking' - (default) The initial navigation starts after the * root component has been created. The bootstrap is not blocked on the completion of the initial * navigation. * * 'enabledBlocking' - The initial navigation starts before the root component is created. * The bootstrap is blocked until the initial navigation is complete. This value should be set in * case you use [server-side rendering](guide/ssr), but do not enable [hydration](guide/hydration) * for your application. * * 'disabled' - The initial navigation is not performed. The location listener is set up before * the root component gets created. Use if there is a reason to have * more control over when the router starts its initial navigation due to some complex * initialization logic. * * @see {@link forRoot()} * * @publicApi */ export declare type InitialNavigation = 'disabled' | 'enabledBlocking' | 'enabledNonBlocking'; /** * A type alias for providers returned by `withEnabledBlockingInitialNavigation` or * `withDisabledInitialNavigation` functions for use with `provideRouter`. * * @see {@link withEnabledBlockingInitialNavigation} * @see {@link withDisabledInitialNavigation} * @see {@link provideRouter} * * @publicApi */ export declare type InitialNavigationFeature = EnabledBlockingInitialNavigationFeature | DisabledInitialNavigationFeature; /** * A type alias for providers returned by `withInMemoryScrolling` for use with `provideRouter`. * * @see {@link withInMemoryScrolling} * @see {@link provideRouter} * * @publicApi */ export declare type InMemoryScrollingFeature = RouterFeature<RouterFeatureKind.InMemoryScrollingFeature>; /** * Configuration options for the scrolling feature which can be used with `withInMemoryScrolling` * function. * * @publicApi */ export declare interface InMemoryScrollingOptions { /** * When set to 'enabled', scrolls to the anchor element when the URL has a fragment. * Anchor scrolling is disabled by default. * * Anchor scrolling does not happen on 'popstate'. Instead, we restore the position * that we stored or scroll to the top. */ anchorScrolling?: 'disabled' | 'enabled'; /** * Configures if the scroll position needs to be restored when navigating back. * * * 'disabled'- (Default) Does nothing. Scroll position is maintained on navigation. * * 'top'- Sets the scroll position to x = 0, y = 0 on all navigation. * * 'enabled'- Restores the previous scroll position on backward navigation, else sets the * position to the anchor if one is provided, or sets the scroll position to [0, 0] (forward * navigation). This option will be the default in the future. * * You can implement custom scroll restoration behavior by adapting the enabled behavior as * in the following example. * * ```typescript * class AppComponent { * movieData: any; * * constructor(private router: Router, private viewportScroller: ViewportScroller, * changeDetectorRef: ChangeDetectorRef) { * router.events.pipe(filter((event: Event): event is Scroll => event instanceof Scroll) * ).subscribe(e => { * fetch('http://example.com/movies.json').then(response => { * this.movieData = response.json(); * // update the template with the data before restoring scroll * changeDetectorRef.detectChanges(); * * if (e.position) { * viewportScroller.scrollToPosition(e.position); * } * }); * }); * } * } * ``` */ scrollPositionRestoration?: 'disabled' | 'enabled' | 'top'; } declare const INPUT_BINDER: InjectionToken<RoutedComponentInputBinder>; /** * A set of options which specify how to determine if a `UrlTree` is active, given the `UrlTree` * for the current router state. * * @publicApi * @see {@link Router#isActive} */ export declare interface IsActiveMatchOptions { /** * Defines the strategy for comparing the matrix parameters of two `UrlTree`s. * * The matrix parameter matching is dependent on the strategy for matching the * segments. That is, if the `paths` option is set to `'subset'`, only * the matrix parameters of the matching segments will be compared. * * - `'exact'`: Requires that matching segments also have exact matrix parameter * matches. * - `'subset'`: The matching segments in the router's active `UrlTree` may contain * extra matrix parameters, but those that exist in the `UrlTree` in question must match. * - `'ignored'`: When comparing `UrlTree`s, matrix params will be ignored. */ matrixParams: 'exact' | 'subset' | 'ignored'; /** * Defines the strategy for comparing the query parameters of two `UrlTree`s. * * - `'exact'`: the query parameters must match exactly. * - `'subset'`: the active `UrlTree` may contain extra parameters, * but must match the key and value of any that exist in the `UrlTree` in question. * - `'ignored'`: When comparing `UrlTree`s, query params will be ignored. */ queryParams: 'exact' | 'subset' | 'ignored'; /** * Defines the strategy for comparing the `UrlSegment`s of the `UrlTree`s. * * - `'exact'`: all segments in each `UrlTree` must match. * - `'subset'`: a `UrlTree` will be determined to be active if it * is a subtree of the active route. That is, the active route may contain extra * segments, but must at least have all the segments of the `UrlTree` in question. */ paths: 'exact' | 'subset'; /** * - `'exact'`: indicates that the `UrlTree` fragments must be equal. * - `'ignored'`: the fragments will not be compared when determining if a * `UrlTree` is active. */ fragment: 'exact' | 'ignored'; } /** * * A function that returns a set of routes to load. * * @see {@link LoadChildrenCallback} * @publicApi */ export declare type LoadChildren = LoadChildrenCallback; /** * * A function that is called to resolve a collection of lazy-loaded routes. * Must be an arrow function of the following form: * `() => import('...').then(mod => mod.MODULE)` * or * `() => import('...').then(mod => mod.ROUTES)` * * For example: * * ``` * [{ * path: 'lazy', * loadChildren: () => import('./lazy-route/lazy.module').then(mod => mod.LazyModule), * }]; * ``` * or * ``` * [{ * path: 'lazy', * loadChildren: () => import('./lazy-route/lazy.routes').then(mod => mod.ROUTES), * }]; * ``` * * If the lazy-loaded routes are exported via a `default` export, the `.then` can be omitted: * ``` * [{ * path: 'lazy', * loadChildren: () => import('./lazy-route/lazy.routes'), * }]; * ``` * * @see {@link Route#loadChildren} * @publicApi */ export declare 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>>; declare interface LoadedRouterConfig { routes: Route[]; injector: EnvironmentInjector | undefined; } /** * Maps an array of injectable classes with canActivate functions to an array of equivalent * `CanActivateFn` for use in a `Route` definition. * * Usage {@example router/utils/functional_guards.ts region='CanActivate'} * * @publicApi * @see {@link Route} */ export declare function mapToCanActivate(providers: Array<Type<CanActivate>>): CanActivateFn[]; /** * Maps an array of injectable classes with canActivateChild functions to an array of equivalent * `CanActivateChildFn` for use in a `Route` definition. * * Usage {@example router/utils/functional_guards.ts region='CanActivate'} * * @publicApi * @see {@link Route} */ export declare function mapToCanActivateChild(providers: Array<Type<CanActivateChild>>): CanActivateChildFn[]; /** * Maps an array of injectable classes with canDeactivate functions to an array of equivalent * `CanDeactivateFn` for use in a `Route` definition. * * Usage {@example router/utils/functional_guards.ts region='CanActivate'} * * @publicApi * @see {@link Route} */ export declare function mapToCanDeactivate<T = unknown>(providers: Array<Type<CanDeactivate<T>>>): CanDeactivateFn<T>[]; /** * Maps an array of injectable classes with canMatch functions to an array of equivalent * `CanMatchFn` for use in a `Route` definition. * * Usage {@example router/utils/functional_guards.ts region='CanActivate'} * * @publicApi * @see {@link Route} */ export declare function mapToCanMatch(providers: Array<Type<CanMatch>>): CanMatchFn[]; /** * Maps an injectable class with a resolve function to an equivalent `ResolveFn` * for use in a `Route` definition. * * Usage {@example router/utils/functional_guards.ts region='Resolve'} * * @publicApi * @see {@link Route} */ export declare function mapToResolve<T>(provider: Type<Resolve<T>>): ResolveFn<T>; /** * Type used to represent a value which may be synchronous or async. * * @publicApi */ export declare type MaybeAsync<T> = T | Observable<T> | Promise<T>; /** * Information about a navigation operation. * Retrieve the most recent navigation object with the * [Router.getCurrentNavigation() method](api/router/Router#getcurrentnavigation) . * * * *id* : The unique identifier of the current navigation. * * *initialUrl* : The target URL passed into the `Router#navigateByUrl()` call before navigation. * This is the value before the router has parsed or applied redirects to it. * * *extractedUrl* : The initial target URL after being parsed with `UrlSerializer.extract()`. * * *finalUrl* : The extracted URL after redirects have been applied. * This URL may not be available immediately, therefore this property can be `undefined`. * It is guaranteed to be set after the