MCPcopy Index your code
hub / github.com/angular/angular / Router

Class Router

packages/router/src/router.ts:88–711  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86 */
87@Service()
88export class Router {
89 private get currentUrlTree() {
90 return this.stateManager.getCurrentUrlTree();
91 }
92 private get rawUrlTree() {
93 return this.stateManager.getRawUrlTree();
94 }
95 private disposed = false;
96 private nonRouterCurrentEntryChangeSubscription?: SubscriptionLike;
97
98 private readonly console = inject(Console);
99 private readonly stateManager = inject(StateManager);
100 private readonly options = inject(ROUTER_CONFIGURATION, {optional: true}) || {};
101 private readonly pendingTasks = inject(PendingTasks);
102 private readonly urlUpdateStrategy = this.options.urlUpdateStrategy || 'deferred';
103 private readonly navigationTransitions = inject(NavigationTransitions);
104 private readonly urlSerializer = inject(UrlSerializer);
105 private readonly location = inject(Location);
106 private readonly urlHandlingStrategy = inject(UrlHandlingStrategy);
107 private readonly injector = inject(EnvironmentInjector);
108
109 /**
110 * The private `Subject` type for the public events exposed in the getter. This is used internally
111 * to push events to. The separate field allows us to expose separate types in the public API
112 * (i.e., an Observable rather than the Subject).
113 */
114 private _events = new Subject<Event>();
115 /**
116 * An event stream for routing events.
117 */
118 public get events(): Observable<Event> {
119 // TODO(atscott): This _should_ be events.asObservable(). However, this change requires internal
120 // cleanup: tests are doing `(route.events as Subject<Event>).next(...)`. This isn't
121 // allowed/supported but we still have to fix these or file bugs against the teams before making
122 // the change.
123 return this._events;
124 }
125 /**
126 * The current state of routing in this NgModule.
127 */
128 get routerState(): RouterState {
129 return this.stateManager.getRouterState();
130 }
131
132 /**
133 * True if at least one navigation event has occurred,
134 * false otherwise.
135 */
136 navigated: boolean = false;
137
138 /**
139 * A strategy for re-using routes.
140 *
141 * @deprecated Configure using `providers` instead:
142 * `{provide: RouteReuseStrategy, useClass: MyStrategy}`.
143 */
144 routeReuseStrategy: RouteReuseStrategy = inject(RouteReuseStrategy);
145

Callers

nothing calls this directly

Calls 2

injectFunction · 0.90
asReadonlyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…