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

Method onUrlChange

packages/common/src/location/location.ts:226–242  ·  view source on GitHub ↗

* Registers a URL change listener. Use to catch updates performed by the Angular * framework that are not detectible through "popstate" or "hashchange" events. * * @param fn The change handler function, which take a URL and a location history state. * @returns A function that, when execu

(fn: (url: string, state: unknown) => void)

Source from the content-addressed store, hash-verified

224 * @returns A function that, when executed, unregisters a URL change listener.
225 */
226 onUrlChange(fn: (url: string, state: unknown) => void): VoidFunction {
227 this._urlChangeListeners.push(fn);
228
229 this._urlChangeSubscription ??= this.subscribe((v) => {
230 this._notifyUrlChangeListeners(v.url, v.state);
231 });
232
233 return () => {
234 const fnIndex = this._urlChangeListeners.indexOf(fn);
235 this._urlChangeListeners.splice(fnIndex, 1);
236
237 if (this._urlChangeListeners.length === 0) {
238 this._urlChangeSubscription?.unsubscribe();
239 this._urlChangeSubscription = null;
240 }
241 };
242 }
243
244 /** @internal */
245 _notifyUrlChangeListeners(url: string = '', state: unknown) {

Implementers 1

SpyLocationpackages/common/testing/src/location_m

Calls 5

subscribeMethod · 0.95
indexOfMethod · 0.80
unsubscribeMethod · 0.65
pushMethod · 0.45