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

Method browserUrl

packages/common/upgrade/src/location_shim.ts:274–314  ·  view source on GitHub ↗
(url?: string, replace?: boolean, state?: unknown)

Source from the content-addressed store, hash-verified

272 private browserUrl(): string;
273 private browserUrl(url: string, replace?: boolean, state?: unknown): this;
274 private browserUrl(url?: string, replace?: boolean, state?: unknown) {
275 // In modern browsers `history.state` is `null` by default; treating it separately
276 // from `undefined` would cause `$browser.url('/foo')` to change `history.state`
277 // to undefined via `pushState`. Instead, let's change `undefined` to `null` here.
278 if (typeof state === 'undefined') {
279 state = null;
280 }
281
282 // setter
283 if (url) {
284 let sameState = this.lastHistoryState === state;
285
286 // Normalize the inputted URL
287 url = this.urlCodec.parse(url).href;
288
289 // Don't change anything if previous and current URLs and states match.
290 if (this.lastBrowserUrl === url && sameState) {
291 return this;
292 }
293 this.lastBrowserUrl = url;
294 this.lastHistoryState = state;
295
296 // Remove server base from URL as the Angular APIs for updating URL require
297 // it to be the path+.
298 url = this.stripBaseUrl(this.getServerBase(), url) || url;
299
300 // Set the URL
301 if (replace) {
302 this.locationStrategy.replaceState(state, '', url, '');
303 } else {
304 this.locationStrategy.pushState(state, '', url, '');
305 }
306
307 this.cacheState();
308
309 return this;
310 // getter
311 } else {
312 return this.platformLocation.href;
313 }
314 }
315
316 // This variable should be used *only* inside the cacheState function.
317 private lastCachedState: unknown = null;

Callers 5

constructorMethod · 0.95
initializeMethod · 0.95
resetBrowserUpdateMethod · 0.95
onClickMethod · 0.80

Calls 6

stripBaseUrlMethod · 0.95
getServerBaseMethod · 0.95
cacheStateMethod · 0.95
parseMethod · 0.65
replaceStateMethod · 0.45
pushStateMethod · 0.45

Tested by

no test coverage detected