MCPcopy Create free account
hub / github.com/angular/angular / browserUrl

Method browserUrl

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

Source from the content-addressed store, hash-verified

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