@angular/common 21.0.0-next.9 → 21.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v21.0.0-next.9
2
+ * @license Angular v21.0.0-rc.1
3
3
  * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
@@ -10,627 +10,431 @@ import { Subject } from 'rxjs';
10
10
 
11
11
  let _DOM = null;
12
12
  function getDOM() {
13
- return _DOM;
13
+ return _DOM;
14
14
  }
15
15
  function setRootDomAdapter(adapter) {
16
- _DOM ??= adapter;
17
- }
18
- /**
19
- * Provides DOM operations in an environment-agnostic way.
20
- *
21
- * @security Tread carefully! Interacting with the DOM directly is dangerous and
22
- * can introduce XSS risks.
23
- */
24
- class DomAdapter {
16
+ _DOM ??= adapter;
25
17
  }
18
+ class DomAdapter {}
26
19
 
27
- /**
28
- * This class should not be used directly by an application developer. Instead, use
29
- * {@link Location}.
30
- *
31
- * `PlatformLocation` encapsulates all calls to DOM APIs, which allows the Router to be
32
- * platform-agnostic.
33
- * This means that we can have different implementation of `PlatformLocation` for the different
34
- * platforms that Angular supports. For example, `@angular/platform-browser` provides an
35
- * implementation specific to the browser environment, while `@angular/platform-server` provides
36
- * one suitable for use with server-side rendering.
37
- *
38
- * The `PlatformLocation` class is used directly by all implementations of {@link LocationStrategy}
39
- * when they need to interact with the DOM APIs like pushState, popState, etc.
40
- *
41
- * {@link LocationStrategy} in turn is used by the {@link Location} service which is used directly
42
- * by the {@link /api/router/Router Router} in order to navigate between routes. Since all interactions between
43
- * {@link /api/router/Router Router} /
44
- * {@link Location} / {@link LocationStrategy} and DOM APIs flow through the `PlatformLocation`
45
- * class, they are all platform-agnostic.
46
- *
47
- * @publicApi
48
- */
49
20
  class PlatformLocation {
50
- historyGo(relativePosition) {
51
- throw new Error(ngDevMode ? 'Not implemented' : '');
52
- }
53
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: PlatformLocation, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
54
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: PlatformLocation, providedIn: 'platform', useFactory: () => inject(BrowserPlatformLocation) });
21
+ historyGo(relativePosition) {
22
+ throw new Error(ngDevMode ? 'Not implemented' : '');
23
+ }
24
+ static ɵfac = i0.ɵɵngDeclareFactory({
25
+ minVersion: "12.0.0",
26
+ version: "21.0.0-rc.1",
27
+ ngImport: i0,
28
+ type: PlatformLocation,
29
+ deps: [],
30
+ target: i0.ɵɵFactoryTarget.Injectable
31
+ });
32
+ static ɵprov = i0.ɵɵngDeclareInjectable({
33
+ minVersion: "12.0.0",
34
+ version: "21.0.0-rc.1",
35
+ ngImport: i0,
36
+ type: PlatformLocation,
37
+ providedIn: 'platform',
38
+ useFactory: () => inject(BrowserPlatformLocation)
39
+ });
55
40
  }
56
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: PlatformLocation, decorators: [{
57
- type: Injectable,
58
- args: [{ providedIn: 'platform', useFactory: () => inject(BrowserPlatformLocation) }]
59
- }] });
60
- /**
61
- * @description
62
- * Indicates when a location is initialized.
63
- *
64
- * @publicApi
65
- */
41
+ i0.ɵɵngDeclareClassMetadata({
42
+ minVersion: "12.0.0",
43
+ version: "21.0.0-rc.1",
44
+ ngImport: i0,
45
+ type: PlatformLocation,
46
+ decorators: [{
47
+ type: Injectable,
48
+ args: [{
49
+ providedIn: 'platform',
50
+ useFactory: () => inject(BrowserPlatformLocation)
51
+ }]
52
+ }]
53
+ });
66
54
  const LOCATION_INITIALIZED = new InjectionToken(typeof ngDevMode !== undefined && ngDevMode ? 'Location Initialized' : '');
67
- /**
68
- * `PlatformLocation` encapsulates all of the direct calls to platform APIs.
69
- * This class should not be used directly by an application developer. Instead, use
70
- * {@link Location}.
71
- *
72
- * @publicApi
73
- */
74
55
  class BrowserPlatformLocation extends PlatformLocation {
75
- _location;
76
- _history;
77
- _doc = inject(DOCUMENT);
78
- constructor() {
79
- super();
80
- this._location = window.location;
81
- this._history = window.history;
82
- }
83
- getBaseHrefFromDOM() {
84
- return getDOM().getBaseHref(this._doc);
85
- }
86
- onPopState(fn) {
87
- const window = getDOM().getGlobalEventTarget(this._doc, 'window');
88
- window.addEventListener('popstate', fn, false);
89
- return () => window.removeEventListener('popstate', fn);
90
- }
91
- onHashChange(fn) {
92
- const window = getDOM().getGlobalEventTarget(this._doc, 'window');
93
- window.addEventListener('hashchange', fn, false);
94
- return () => window.removeEventListener('hashchange', fn);
95
- }
96
- get href() {
97
- return this._location.href;
98
- }
99
- get protocol() {
100
- return this._location.protocol;
101
- }
102
- get hostname() {
103
- return this._location.hostname;
104
- }
105
- get port() {
106
- return this._location.port;
107
- }
108
- get pathname() {
109
- return this._location.pathname;
110
- }
111
- get search() {
112
- return this._location.search;
113
- }
114
- get hash() {
115
- return this._location.hash;
116
- }
117
- set pathname(newPath) {
118
- this._location.pathname = newPath;
119
- }
120
- pushState(state, title, url) {
121
- this._history.pushState(state, title, url);
122
- }
123
- replaceState(state, title, url) {
124
- this._history.replaceState(state, title, url);
125
- }
126
- forward() {
127
- this._history.forward();
128
- }
129
- back() {
130
- this._history.back();
131
- }
132
- historyGo(relativePosition = 0) {
133
- this._history.go(relativePosition);
134
- }
135
- getState() {
136
- return this._history.state;
137
- }
138
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: BrowserPlatformLocation, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
139
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: BrowserPlatformLocation, providedIn: 'platform', useFactory: () => new BrowserPlatformLocation() });
56
+ _location;
57
+ _history;
58
+ _doc = inject(DOCUMENT);
59
+ constructor() {
60
+ super();
61
+ this._location = window.location;
62
+ this._history = window.history;
63
+ }
64
+ getBaseHrefFromDOM() {
65
+ return getDOM().getBaseHref(this._doc);
66
+ }
67
+ onPopState(fn) {
68
+ const window = getDOM().getGlobalEventTarget(this._doc, 'window');
69
+ window.addEventListener('popstate', fn, false);
70
+ return () => window.removeEventListener('popstate', fn);
71
+ }
72
+ onHashChange(fn) {
73
+ const window = getDOM().getGlobalEventTarget(this._doc, 'window');
74
+ window.addEventListener('hashchange', fn, false);
75
+ return () => window.removeEventListener('hashchange', fn);
76
+ }
77
+ get href() {
78
+ return this._location.href;
79
+ }
80
+ get protocol() {
81
+ return this._location.protocol;
82
+ }
83
+ get hostname() {
84
+ return this._location.hostname;
85
+ }
86
+ get port() {
87
+ return this._location.port;
88
+ }
89
+ get pathname() {
90
+ return this._location.pathname;
91
+ }
92
+ get search() {
93
+ return this._location.search;
94
+ }
95
+ get hash() {
96
+ return this._location.hash;
97
+ }
98
+ set pathname(newPath) {
99
+ this._location.pathname = newPath;
100
+ }
101
+ pushState(state, title, url) {
102
+ this._history.pushState(state, title, url);
103
+ }
104
+ replaceState(state, title, url) {
105
+ this._history.replaceState(state, title, url);
106
+ }
107
+ forward() {
108
+ this._history.forward();
109
+ }
110
+ back() {
111
+ this._history.back();
112
+ }
113
+ historyGo(relativePosition = 0) {
114
+ this._history.go(relativePosition);
115
+ }
116
+ getState() {
117
+ return this._history.state;
118
+ }
119
+ static ɵfac = i0.ɵɵngDeclareFactory({
120
+ minVersion: "12.0.0",
121
+ version: "21.0.0-rc.1",
122
+ ngImport: i0,
123
+ type: BrowserPlatformLocation,
124
+ deps: [],
125
+ target: i0.ɵɵFactoryTarget.Injectable
126
+ });
127
+ static ɵprov = i0.ɵɵngDeclareInjectable({
128
+ minVersion: "12.0.0",
129
+ version: "21.0.0-rc.1",
130
+ ngImport: i0,
131
+ type: BrowserPlatformLocation,
132
+ providedIn: 'platform',
133
+ useFactory: () => new BrowserPlatformLocation()
134
+ });
140
135
  }
141
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: BrowserPlatformLocation, decorators: [{
142
- type: Injectable,
143
- args: [{
144
- providedIn: 'platform',
145
- useFactory: () => new BrowserPlatformLocation(),
146
- }]
147
- }], ctorParameters: () => [] });
136
+ i0.ɵɵngDeclareClassMetadata({
137
+ minVersion: "12.0.0",
138
+ version: "21.0.0-rc.1",
139
+ ngImport: i0,
140
+ type: BrowserPlatformLocation,
141
+ decorators: [{
142
+ type: Injectable,
143
+ args: [{
144
+ providedIn: 'platform',
145
+ useFactory: () => new BrowserPlatformLocation()
146
+ }]
147
+ }],
148
+ ctorParameters: () => []
149
+ });
148
150
 
149
- /**
150
- * Joins two parts of a URL with a slash if needed.
151
- *
152
- * @param start URL string
153
- * @param end URL string
154
- *
155
- *
156
- * @returns The joined URL string.
157
- */
158
151
  function joinWithSlash(start, end) {
159
- // If `start` is an empty string, return `end` as the result.
160
- if (!start)
161
- return end;
162
- // If `end` is an empty string, return `start` as the result.
163
- if (!end)
164
- return start;
165
- // If `start` ends with a slash, remove the leading slash from `end`.
166
- if (start.endsWith('/')) {
167
- return end.startsWith('/') ? start + end.slice(1) : start + end;
168
- }
169
- // If `start` doesn't end with a slash, add one if `end` doesn't start with a slash.
170
- return end.startsWith('/') ? start + end : `${start}/${end}`;
152
+ if (!start) return end;
153
+ if (!end) return start;
154
+ if (start.endsWith('/')) {
155
+ return end.startsWith('/') ? start + end.slice(1) : start + end;
156
+ }
157
+ return end.startsWith('/') ? start + end : `${start}/${end}`;
171
158
  }
172
- /**
173
- * Removes a trailing slash from a URL string if needed.
174
- * Looks for the first occurrence of either `#`, `?`, or the end of the
175
- * line as `/` characters and removes the trailing slash if one exists.
176
- *
177
- * @param url URL string.
178
- *
179
- * @returns The URL string, modified if needed.
180
- */
181
159
  function stripTrailingSlash(url) {
182
- // Find the index of the first occurrence of `#`, `?`, or the end of the string.
183
- // This marks the start of the query string, fragment, or the end of the URL path.
184
- const pathEndIdx = url.search(/#|\?|$/);
185
- // Check if the character before `pathEndIdx` is a trailing slash.
186
- // If it is, remove the trailing slash and return the modified URL.
187
- // Otherwise, return the URL as is.
188
- return url[pathEndIdx - 1] === '/' ? url.slice(0, pathEndIdx - 1) + url.slice(pathEndIdx) : url;
160
+ const pathEndIdx = url.search(/#|\?|$/);
161
+ return url[pathEndIdx - 1] === '/' ? url.slice(0, pathEndIdx - 1) + url.slice(pathEndIdx) : url;
189
162
  }
190
- /**
191
- * Normalizes URL parameters by prepending with `?` if needed.
192
- *
193
- * @param params String of URL parameters.
194
- *
195
- * @returns The normalized URL parameters string.
196
- */
197
163
  function normalizeQueryParams(params) {
198
- return params && params[0] !== '?' ? `?${params}` : params;
164
+ return params && params[0] !== '?' ? `?${params}` : params;
199
165
  }
200
166
 
201
- /**
202
- * Enables the `Location` service to read route state from the browser's URL.
203
- * Angular provides two strategies:
204
- * `HashLocationStrategy` and `PathLocationStrategy`.
205
- *
206
- * Applications should use the `Router` or `Location` services to
207
- * interact with application route state.
208
- *
209
- * For instance, `HashLocationStrategy` produces URLs like
210
- * <code class="no-auto-link">http://example.com/#/foo</code>,
211
- * and `PathLocationStrategy` produces
212
- * <code class="no-auto-link">http://example.com/foo</code> as an equivalent URL.
213
- *
214
- * See these two classes for more.
215
- *
216
- * @publicApi
217
- */
218
167
  class LocationStrategy {
219
- historyGo(relativePosition) {
220
- throw new Error(ngDevMode ? 'Not implemented' : '');
221
- }
222
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: LocationStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
223
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: LocationStrategy, providedIn: 'root', useFactory: () => inject(PathLocationStrategy) });
168
+ historyGo(relativePosition) {
169
+ throw new Error(ngDevMode ? 'Not implemented' : '');
170
+ }
171
+ static ɵfac = i0.ɵɵngDeclareFactory({
172
+ minVersion: "12.0.0",
173
+ version: "21.0.0-rc.1",
174
+ ngImport: i0,
175
+ type: LocationStrategy,
176
+ deps: [],
177
+ target: i0.ɵɵFactoryTarget.Injectable
178
+ });
179
+ static ɵprov = i0.ɵɵngDeclareInjectable({
180
+ minVersion: "12.0.0",
181
+ version: "21.0.0-rc.1",
182
+ ngImport: i0,
183
+ type: LocationStrategy,
184
+ providedIn: 'root',
185
+ useFactory: () => inject(PathLocationStrategy)
186
+ });
224
187
  }
225
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: LocationStrategy, decorators: [{
226
- type: Injectable,
227
- args: [{ providedIn: 'root', useFactory: () => inject(PathLocationStrategy) }]
228
- }] });
229
- /**
230
- * A predefined DI token for the base href
231
- * to be used with the `PathLocationStrategy`.
232
- * The base href is the URL prefix that should be preserved when generating
233
- * and recognizing URLs.
234
- *
235
- * @usageNotes
236
- *
237
- * The following example shows how to use this token to configure the root app injector
238
- * with a base href value, so that the DI framework can supply the dependency anywhere in the app.
239
- *
240
- * ```ts
241
- * import {NgModule} from '@angular/core';
242
- * import {APP_BASE_HREF} from '@angular/common';
243
- *
244
- * @NgModule({
245
- * providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
246
- * })
247
- * class AppModule {}
248
- * ```
249
- *
250
- * @publicApi
251
- */
188
+ i0.ɵɵngDeclareClassMetadata({
189
+ minVersion: "12.0.0",
190
+ version: "21.0.0-rc.1",
191
+ ngImport: i0,
192
+ type: LocationStrategy,
193
+ decorators: [{
194
+ type: Injectable,
195
+ args: [{
196
+ providedIn: 'root',
197
+ useFactory: () => inject(PathLocationStrategy)
198
+ }]
199
+ }]
200
+ });
252
201
  const APP_BASE_HREF = new InjectionToken(typeof ngDevMode !== undefined && ngDevMode ? 'appBaseHref' : '');
253
- /**
254
- * @description
255
- * A {@link LocationStrategy} used to configure the {@link Location} service to
256
- * represent its state in the
257
- * [path](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) of the
258
- * browser's URL.
259
- *
260
- * If you're using `PathLocationStrategy`, you may provide a {@link APP_BASE_HREF}
261
- * or add a `<base href>` element to the document to override the default.
262
- *
263
- * For instance, if you provide an `APP_BASE_HREF` of `'/my/app/'` and call
264
- * `location.go('/foo')`, the browser's URL will become
265
- * `example.com/my/app/foo`. To ensure all relative URIs resolve correctly,
266
- * the `<base href>` and/or `APP_BASE_HREF` should end with a `/`.
267
- *
268
- * Similarly, if you add `<base href='/my/app/'/>` to the document and call
269
- * `location.go('/foo')`, the browser's URL will become
270
- * `example.com/my/app/foo`.
271
- *
272
- * Note that when using `PathLocationStrategy`, neither the query nor
273
- * the fragment in the `<base href>` will be preserved, as outlined
274
- * by the [RFC](https://tools.ietf.org/html/rfc3986#section-5.2.2).
275
- *
276
- * @usageNotes
277
- *
278
- * ### Example
279
- *
280
- * {@example common/location/ts/path_location_component.ts region='LocationComponent'}
281
- *
282
- * @publicApi
283
- */
284
202
  class PathLocationStrategy extends LocationStrategy {
285
- _platformLocation;
286
- _baseHref;
287
- _removeListenerFns = [];
288
- constructor(_platformLocation, href) {
289
- super();
290
- this._platformLocation = _platformLocation;
291
- this._baseHref =
292
- href ??
293
- this._platformLocation.getBaseHrefFromDOM() ??
294
- inject(DOCUMENT).location?.origin ??
295
- '';
296
- }
297
- /** @docs-private */
298
- ngOnDestroy() {
299
- while (this._removeListenerFns.length) {
300
- this._removeListenerFns.pop()();
301
- }
302
- }
303
- onPopState(fn) {
304
- this._removeListenerFns.push(this._platformLocation.onPopState(fn), this._platformLocation.onHashChange(fn));
305
- }
306
- getBaseHref() {
307
- return this._baseHref;
308
- }
309
- prepareExternalUrl(internal) {
310
- return joinWithSlash(this._baseHref, internal);
311
- }
312
- path(includeHash = false) {
313
- const pathname = this._platformLocation.pathname + normalizeQueryParams(this._platformLocation.search);
314
- const hash = this._platformLocation.hash;
315
- return hash && includeHash ? `${pathname}${hash}` : pathname;
316
- }
317
- pushState(state, title, url, queryParams) {
318
- const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
319
- this._platformLocation.pushState(state, title, externalUrl);
320
- }
321
- replaceState(state, title, url, queryParams) {
322
- const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
323
- this._platformLocation.replaceState(state, title, externalUrl);
324
- }
325
- forward() {
326
- this._platformLocation.forward();
327
- }
328
- back() {
329
- this._platformLocation.back();
330
- }
331
- getState() {
332
- return this._platformLocation.getState();
333
- }
334
- historyGo(relativePosition = 0) {
335
- this._platformLocation.historyGo?.(relativePosition);
336
- }
337
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: PathLocationStrategy, deps: [{ token: PlatformLocation }, { token: APP_BASE_HREF, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
338
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: PathLocationStrategy, providedIn: 'root' });
203
+ _platformLocation;
204
+ _baseHref;
205
+ _removeListenerFns = [];
206
+ constructor(_platformLocation, href) {
207
+ super();
208
+ this._platformLocation = _platformLocation;
209
+ this._baseHref = href ?? this._platformLocation.getBaseHrefFromDOM() ?? inject(DOCUMENT).location?.origin ?? '';
210
+ }
211
+ ngOnDestroy() {
212
+ while (this._removeListenerFns.length) {
213
+ this._removeListenerFns.pop()();
214
+ }
215
+ }
216
+ onPopState(fn) {
217
+ this._removeListenerFns.push(this._platformLocation.onPopState(fn), this._platformLocation.onHashChange(fn));
218
+ }
219
+ getBaseHref() {
220
+ return this._baseHref;
221
+ }
222
+ prepareExternalUrl(internal) {
223
+ return joinWithSlash(this._baseHref, internal);
224
+ }
225
+ path(includeHash = false) {
226
+ const pathname = this._platformLocation.pathname + normalizeQueryParams(this._platformLocation.search);
227
+ const hash = this._platformLocation.hash;
228
+ return hash && includeHash ? `${pathname}${hash}` : pathname;
229
+ }
230
+ pushState(state, title, url, queryParams) {
231
+ const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
232
+ this._platformLocation.pushState(state, title, externalUrl);
233
+ }
234
+ replaceState(state, title, url, queryParams) {
235
+ const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
236
+ this._platformLocation.replaceState(state, title, externalUrl);
237
+ }
238
+ forward() {
239
+ this._platformLocation.forward();
240
+ }
241
+ back() {
242
+ this._platformLocation.back();
243
+ }
244
+ getState() {
245
+ return this._platformLocation.getState();
246
+ }
247
+ historyGo(relativePosition = 0) {
248
+ this._platformLocation.historyGo?.(relativePosition);
249
+ }
250
+ static ɵfac = i0.ɵɵngDeclareFactory({
251
+ minVersion: "12.0.0",
252
+ version: "21.0.0-rc.1",
253
+ ngImport: i0,
254
+ type: PathLocationStrategy,
255
+ deps: [{
256
+ token: PlatformLocation
257
+ }, {
258
+ token: APP_BASE_HREF,
259
+ optional: true
260
+ }],
261
+ target: i0.ɵɵFactoryTarget.Injectable
262
+ });
263
+ static ɵprov = i0.ɵɵngDeclareInjectable({
264
+ minVersion: "12.0.0",
265
+ version: "21.0.0-rc.1",
266
+ ngImport: i0,
267
+ type: PathLocationStrategy,
268
+ providedIn: 'root'
269
+ });
339
270
  }
340
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: PathLocationStrategy, decorators: [{
341
- type: Injectable,
342
- args: [{ providedIn: 'root' }]
343
- }], ctorParameters: () => [{ type: PlatformLocation }, { type: undefined, decorators: [{
344
- type: Optional
345
- }, {
346
- type: Inject,
347
- args: [APP_BASE_HREF]
348
- }] }] });
271
+ i0.ɵɵngDeclareClassMetadata({
272
+ minVersion: "12.0.0",
273
+ version: "21.0.0-rc.1",
274
+ ngImport: i0,
275
+ type: PathLocationStrategy,
276
+ decorators: [{
277
+ type: Injectable,
278
+ args: [{
279
+ providedIn: 'root'
280
+ }]
281
+ }],
282
+ ctorParameters: () => [{
283
+ type: PlatformLocation
284
+ }, {
285
+ type: undefined,
286
+ decorators: [{
287
+ type: Optional
288
+ }, {
289
+ type: Inject,
290
+ args: [APP_BASE_HREF]
291
+ }]
292
+ }]
293
+ });
349
294
 
350
- /**
351
- * @description
352
- *
353
- * A service that applications can use to interact with a browser's URL.
354
- *
355
- * Depending on the `LocationStrategy` used, `Location` persists
356
- * to the URL's path or the URL's hash segment.
357
- *
358
- * @usageNotes
359
- *
360
- * It's better to use the `Router.navigate()` service to trigger route changes. Use
361
- * `Location` only if you need to interact with or create normalized URLs outside of
362
- * routing.
363
- *
364
- * `Location` is responsible for normalizing the URL against the application's base href.
365
- * A normalized URL is absolute from the URL host, includes the application's base href, and has no
366
- * trailing slash:
367
- * - `/my/app/user/123` is normalized
368
- * - `my/app/user/123` **is not** normalized
369
- * - `/my/app/user/123/` **is not** normalized
370
- *
371
- * ### Example
372
- *
373
- * {@example common/location/ts/path_location_component.ts region='LocationComponent'}
374
- *
375
- * @publicApi
376
- */
377
295
  class Location {
378
- /** @internal */
379
- _subject = new Subject();
380
- /** @internal */
381
- _basePath;
382
- /** @internal */
383
- _locationStrategy;
384
- /** @internal */
385
- _urlChangeListeners = [];
386
- /** @internal */
387
- _urlChangeSubscription = null;
388
- constructor(locationStrategy) {
389
- this._locationStrategy = locationStrategy;
390
- const baseHref = this._locationStrategy.getBaseHref();
391
- // Note: This class's interaction with base HREF does not fully follow the rules
392
- // outlined in the spec https://www.freesoft.org/CIE/RFC/1808/18.htm.
393
- // Instead of trying to fix individual bugs with more and more code, we should
394
- // investigate using the URL constructor and providing the base as a second
395
- // argument.
396
- // https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#parameters
397
- this._basePath = _stripOrigin(stripTrailingSlash(_stripIndexHtml(baseHref)));
398
- this._locationStrategy.onPopState((ev) => {
399
- this._subject.next({
400
- 'url': this.path(true),
401
- 'pop': true,
402
- 'state': ev.state,
403
- 'type': ev.type,
404
- });
405
- });
406
- }
407
- /** @docs-private */
408
- ngOnDestroy() {
296
+ _subject = new Subject();
297
+ _basePath;
298
+ _locationStrategy;
299
+ _urlChangeListeners = [];
300
+ _urlChangeSubscription = null;
301
+ constructor(locationStrategy) {
302
+ this._locationStrategy = locationStrategy;
303
+ const baseHref = this._locationStrategy.getBaseHref();
304
+ this._basePath = _stripOrigin(stripTrailingSlash(_stripIndexHtml(baseHref)));
305
+ this._locationStrategy.onPopState(ev => {
306
+ this._subject.next({
307
+ 'url': this.path(true),
308
+ 'pop': true,
309
+ 'state': ev.state,
310
+ 'type': ev.type
311
+ });
312
+ });
313
+ }
314
+ ngOnDestroy() {
315
+ this._urlChangeSubscription?.unsubscribe();
316
+ this._urlChangeListeners = [];
317
+ }
318
+ path(includeHash = false) {
319
+ return this.normalize(this._locationStrategy.path(includeHash));
320
+ }
321
+ getState() {
322
+ return this._locationStrategy.getState();
323
+ }
324
+ isCurrentPathEqualTo(path, query = '') {
325
+ return this.path() == this.normalize(path + normalizeQueryParams(query));
326
+ }
327
+ normalize(url) {
328
+ return Location.stripTrailingSlash(_stripBasePath(this._basePath, _stripIndexHtml(url)));
329
+ }
330
+ prepareExternalUrl(url) {
331
+ if (url && url[0] !== '/') {
332
+ url = '/' + url;
333
+ }
334
+ return this._locationStrategy.prepareExternalUrl(url);
335
+ }
336
+ go(path, query = '', state = null) {
337
+ this._locationStrategy.pushState(state, '', path, query);
338
+ this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
339
+ }
340
+ replaceState(path, query = '', state = null) {
341
+ this._locationStrategy.replaceState(state, '', path, query);
342
+ this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
343
+ }
344
+ forward() {
345
+ this._locationStrategy.forward();
346
+ }
347
+ back() {
348
+ this._locationStrategy.back();
349
+ }
350
+ historyGo(relativePosition = 0) {
351
+ this._locationStrategy.historyGo?.(relativePosition);
352
+ }
353
+ onUrlChange(fn) {
354
+ this._urlChangeListeners.push(fn);
355
+ this._urlChangeSubscription ??= this.subscribe(v => {
356
+ this._notifyUrlChangeListeners(v.url, v.state);
357
+ });
358
+ return () => {
359
+ const fnIndex = this._urlChangeListeners.indexOf(fn);
360
+ this._urlChangeListeners.splice(fnIndex, 1);
361
+ if (this._urlChangeListeners.length === 0) {
409
362
  this._urlChangeSubscription?.unsubscribe();
410
- this._urlChangeListeners = [];
411
- }
412
- /**
413
- * Normalizes the URL path for this location.
414
- *
415
- * @param includeHash True to include an anchor fragment in the path.
416
- *
417
- * @returns The normalized URL path.
418
- */
419
- // TODO: vsavkin. Remove the boolean flag and always include hash once the deprecated router is
420
- // removed.
421
- path(includeHash = false) {
422
- return this.normalize(this._locationStrategy.path(includeHash));
423
- }
424
- /**
425
- * Reports the current state of the location history.
426
- * @returns The current value of the `history.state` object.
427
- */
428
- getState() {
429
- return this._locationStrategy.getState();
430
- }
431
- /**
432
- * Normalizes the given path and compares to the current normalized path.
433
- *
434
- * @param path The given URL path.
435
- * @param query Query parameters.
436
- *
437
- * @returns True if the given URL path is equal to the current normalized path, false
438
- * otherwise.
439
- */
440
- isCurrentPathEqualTo(path, query = '') {
441
- return this.path() == this.normalize(path + normalizeQueryParams(query));
442
- }
443
- /**
444
- * Normalizes a URL path by stripping any trailing slashes.
445
- *
446
- * @param url String representing a URL.
447
- *
448
- * @returns The normalized URL string.
449
- */
450
- normalize(url) {
451
- return Location.stripTrailingSlash(_stripBasePath(this._basePath, _stripIndexHtml(url)));
452
- }
453
- /**
454
- * Normalizes an external URL path.
455
- * If the given URL doesn't begin with a leading slash (`'/'`), adds one
456
- * before normalizing. Adds a hash if `HashLocationStrategy` is
457
- * in use, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use.
458
- *
459
- * @param url String representing a URL.
460
- *
461
- * @returns A normalized platform-specific URL.
462
- */
463
- prepareExternalUrl(url) {
464
- if (url && url[0] !== '/') {
465
- url = '/' + url;
466
- }
467
- return this._locationStrategy.prepareExternalUrl(url);
468
- }
469
- // TODO: rename this method to pushState
470
- /**
471
- * Changes the browser's URL to a normalized version of a given URL, and pushes a
472
- * new item onto the platform's history.
473
- *
474
- * @param path URL path to normalize.
475
- * @param query Query parameters.
476
- * @param state Location history state.
477
- *
478
- */
479
- go(path, query = '', state = null) {
480
- this._locationStrategy.pushState(state, '', path, query);
481
- this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
482
- }
483
- /**
484
- * Changes the browser's URL to a normalized version of the given URL, and replaces
485
- * the top item on the platform's history stack.
486
- *
487
- * @param path URL path to normalize.
488
- * @param query Query parameters.
489
- * @param state Location history state.
490
- */
491
- replaceState(path, query = '', state = null) {
492
- this._locationStrategy.replaceState(state, '', path, query);
493
- this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
494
- }
495
- /**
496
- * Navigates forward in the platform's history.
497
- */
498
- forward() {
499
- this._locationStrategy.forward();
500
- }
501
- /**
502
- * Navigates back in the platform's history.
503
- */
504
- back() {
505
- this._locationStrategy.back();
506
- }
507
- /**
508
- * Navigate to a specific page from session history, identified by its relative position to the
509
- * current page.
510
- *
511
- * @param relativePosition Position of the target page in the history relative to the current
512
- * page.
513
- * A negative value moves backwards, a positive value moves forwards, e.g. `location.historyGo(2)`
514
- * moves forward two pages and `location.historyGo(-2)` moves back two pages. When we try to go
515
- * beyond what's stored in the history session, we stay in the current page. Same behaviour occurs
516
- * when `relativePosition` equals 0.
517
- * @see https://developer.mozilla.org/en-US/docs/Web/API/History_API#Moving_to_a_specific_point_in_history
518
- */
519
- historyGo(relativePosition = 0) {
520
- this._locationStrategy.historyGo?.(relativePosition);
521
- }
522
- /**
523
- * Registers a URL change listener. Use to catch updates performed by the Angular
524
- * framework that are not detectible through "popstate" or "hashchange" events.
525
- *
526
- * @param fn The change handler function, which take a URL and a location history state.
527
- * @returns A function that, when executed, unregisters a URL change listener.
528
- */
529
- onUrlChange(fn) {
530
- this._urlChangeListeners.push(fn);
531
- this._urlChangeSubscription ??= this.subscribe((v) => {
532
- this._notifyUrlChangeListeners(v.url, v.state);
533
- });
534
- return () => {
535
- const fnIndex = this._urlChangeListeners.indexOf(fn);
536
- this._urlChangeListeners.splice(fnIndex, 1);
537
- if (this._urlChangeListeners.length === 0) {
538
- this._urlChangeSubscription?.unsubscribe();
539
- this._urlChangeSubscription = null;
540
- }
541
- };
542
- }
543
- /** @internal */
544
- _notifyUrlChangeListeners(url = '', state) {
545
- this._urlChangeListeners.forEach((fn) => fn(url, state));
546
- }
547
- /**
548
- * Subscribes to the platform's `popState` events.
549
- *
550
- * Note: `Location.go()` does not trigger the `popState` event in the browser. Use
551
- * `Location.onUrlChange()` to subscribe to URL changes instead.
552
- *
553
- * @param value Event that is triggered when the state history changes.
554
- * @param exception The exception to throw.
555
- *
556
- * @see [onpopstate](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate)
557
- *
558
- * @returns Subscribed events.
559
- */
560
- subscribe(onNext, onThrow, onReturn) {
561
- return this._subject.subscribe({
562
- next: onNext,
563
- error: onThrow ?? undefined,
564
- complete: onReturn ?? undefined,
565
- });
566
- }
567
- /**
568
- * Normalizes URL parameters by prepending with `?` if needed.
569
- *
570
- * @param params String of URL parameters.
571
- *
572
- * @returns The normalized URL parameters string.
573
- */
574
- static normalizeQueryParams = normalizeQueryParams;
575
- /**
576
- * Joins two parts of a URL with a slash if needed.
577
- *
578
- * @param start URL string
579
- * @param end URL string
580
- *
581
- *
582
- * @returns The joined URL string.
583
- */
584
- static joinWithSlash = joinWithSlash;
585
- /**
586
- * Removes a trailing slash from a URL string if needed.
587
- * Looks for the first occurrence of either `#`, `?`, or the end of the
588
- * line as `/` characters and removes the trailing slash if one exists.
589
- *
590
- * @param url URL string.
591
- *
592
- * @returns The URL string, modified if needed.
593
- */
594
- static stripTrailingSlash = stripTrailingSlash;
595
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: Location, deps: [{ token: LocationStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
596
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: Location, providedIn: 'root', useFactory: createLocation });
363
+ this._urlChangeSubscription = null;
364
+ }
365
+ };
366
+ }
367
+ _notifyUrlChangeListeners(url = '', state) {
368
+ this._urlChangeListeners.forEach(fn => fn(url, state));
369
+ }
370
+ subscribe(onNext, onThrow, onReturn) {
371
+ return this._subject.subscribe({
372
+ next: onNext,
373
+ error: onThrow ?? undefined,
374
+ complete: onReturn ?? undefined
375
+ });
376
+ }
377
+ static normalizeQueryParams = normalizeQueryParams;
378
+ static joinWithSlash = joinWithSlash;
379
+ static stripTrailingSlash = stripTrailingSlash;
380
+ static ɵfac = i0.ɵɵngDeclareFactory({
381
+ minVersion: "12.0.0",
382
+ version: "21.0.0-rc.1",
383
+ ngImport: i0,
384
+ type: Location,
385
+ deps: [{
386
+ token: LocationStrategy
387
+ }],
388
+ target: i0.ɵɵFactoryTarget.Injectable
389
+ });
390
+ static ɵprov = i0.ɵɵngDeclareInjectable({
391
+ minVersion: "12.0.0",
392
+ version: "21.0.0-rc.1",
393
+ ngImport: i0,
394
+ type: Location,
395
+ providedIn: 'root',
396
+ useFactory: createLocation
397
+ });
597
398
  }
598
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0-next.9", ngImport: i0, type: Location, decorators: [{
599
- type: Injectable,
600
- args: [{
601
- providedIn: 'root',
602
- // See #23917
603
- useFactory: createLocation,
604
- }]
605
- }], ctorParameters: () => [{ type: LocationStrategy }] });
399
+ i0.ɵɵngDeclareClassMetadata({
400
+ minVersion: "12.0.0",
401
+ version: "21.0.0-rc.1",
402
+ ngImport: i0,
403
+ type: Location,
404
+ decorators: [{
405
+ type: Injectable,
406
+ args: [{
407
+ providedIn: 'root',
408
+ useFactory: createLocation
409
+ }]
410
+ }],
411
+ ctorParameters: () => [{
412
+ type: LocationStrategy
413
+ }]
414
+ });
606
415
  function createLocation() {
607
- return new Location(__inject(LocationStrategy));
416
+ return new Location(__inject(LocationStrategy));
608
417
  }
609
418
  function _stripBasePath(basePath, url) {
610
- if (!basePath || !url.startsWith(basePath)) {
611
- return url;
612
- }
613
- const strippedUrl = url.substring(basePath.length);
614
- if (strippedUrl === '' || ['/', ';', '?', '#'].includes(strippedUrl[0])) {
615
- return strippedUrl;
616
- }
419
+ if (!basePath || !url.startsWith(basePath)) {
617
420
  return url;
421
+ }
422
+ const strippedUrl = url.substring(basePath.length);
423
+ if (strippedUrl === '' || ['/', ';', '?', '#'].includes(strippedUrl[0])) {
424
+ return strippedUrl;
425
+ }
426
+ return url;
618
427
  }
619
428
  function _stripIndexHtml(url) {
620
- return url.replace(/\/index.html$/, '');
429
+ return url.replace(/\/index.html$/, '');
621
430
  }
622
431
  function _stripOrigin(baseHref) {
623
- // DO NOT REFACTOR! Previously, this check looked like this:
624
- // `/^(https?:)?\/\//.test(baseHref)`, but that resulted in
625
- // syntactically incorrect code after Closure Compiler minification.
626
- // This was likely caused by a bug in Closure Compiler, but
627
- // for now, the check is rewritten to use `new RegExp` instead.
628
- const isAbsoluteUrl = new RegExp('^(https?:)?//').test(baseHref);
629
- if (isAbsoluteUrl) {
630
- const [, pathname] = baseHref.split(/\/\/[^\/]+/);
631
- return pathname;
632
- }
633
- return baseHref;
432
+ const isAbsoluteUrl = new RegExp('^(https?:)?//').test(baseHref);
433
+ if (isAbsoluteUrl) {
434
+ const [, pathname] = baseHref.split(/\/\/[^\/]+/);
435
+ return pathname;
436
+ }
437
+ return baseHref;
634
438
  }
635
439
 
636
440
  export { APP_BASE_HREF, BrowserPlatformLocation, DomAdapter, LOCATION_INITIALIZED, Location, LocationStrategy, PathLocationStrategy, PlatformLocation, getDOM, joinWithSlash, normalizeQueryParams, setRootDomAdapter };