Skip to content

Commit 570114e

Browse files
JeanMechealxhub
authored andcommitted
refactor(common): cleanup platformLocation (#50054)
* Drop the usage of @Inject() * Drop `supportsState` as its supported by evergreen browsers. PR Close #50054
1 parent dccfcb7 commit 570114e

File tree

3 files changed

+8
-34
lines changed

3 files changed

+8
-34
lines changed

goldens/public-api/common/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
5252

5353
// @public
5454
export class BrowserPlatformLocation extends PlatformLocation {
55-
constructor(_doc: any);
55+
constructor();
5656
// (undocumented)
5757
back(): void;
5858
// (undocumented)

packages/common/src/location/platform_location.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Inject, Injectable, InjectionToken, ɵɵinject} from '@angular/core';
9+
import {inject, Injectable, InjectionToken} from '@angular/core';
1010

1111
import {getDOM} from '../dom_adapter';
1212
import {DOCUMENT} from '../dom_tokens';
@@ -33,11 +33,7 @@ import {DOCUMENT} from '../dom_tokens';
3333
*
3434
* @publicApi
3535
*/
36-
@Injectable({
37-
providedIn: 'platform',
38-
// See #23917
39-
useFactory: useBrowserPlatformLocation
40-
})
36+
@Injectable({providedIn: 'platform', useFactory: () => inject(BrowserPlatformLocation)})
4137
export abstract class PlatformLocation {
4238
abstract getBaseHrefFromDOM(): string;
4339
abstract getState(): unknown;
@@ -71,10 +67,6 @@ export abstract class PlatformLocation {
7167
}
7268
}
7369

74-
export function useBrowserPlatformLocation() {
75-
return ɵɵinject(BrowserPlatformLocation);
76-
}
77-
7870
/**
7971
* @description
8072
* Indicates when a location is initialized.
@@ -112,14 +104,14 @@ export interface LocationChangeListener {
112104
*/
113105
@Injectable({
114106
providedIn: 'platform',
115-
// See #23917
116-
useFactory: createBrowserPlatformLocation,
107+
useFactory: () => new BrowserPlatformLocation(),
117108
})
118109
export class BrowserPlatformLocation extends PlatformLocation {
119110
private _location: Location;
120111
private _history: History;
112+
private _doc = inject(DOCUMENT);
121113

122-
constructor(@Inject(DOCUMENT) private _doc: any) {
114+
constructor() {
123115
super();
124116
this._location = window.location;
125117
this._history = window.history;
@@ -167,19 +159,11 @@ export class BrowserPlatformLocation extends PlatformLocation {
167159
}
168160

169161
override pushState(state: any, title: string, url: string): void {
170-
if (supportsState()) {
171-
this._history.pushState(state, title, url);
172-
} else {
173-
this._location.hash = url;
174-
}
162+
this._history.pushState(state, title, url);
175163
}
176164

177165
override replaceState(state: any, title: string, url: string): void {
178-
if (supportsState()) {
179-
this._history.replaceState(state, title, url);
180-
} else {
181-
this._location.hash = url;
182-
}
166+
this._history.replaceState(state, title, url);
183167
}
184168

185169
override forward(): void {
@@ -198,10 +182,3 @@ export class BrowserPlatformLocation extends PlatformLocation {
198182
return this._history.state;
199183
}
200184
}
201-
202-
export function supportsState(): boolean {
203-
return !!window.history.pushState;
204-
}
205-
export function createBrowserPlatformLocation() {
206-
return new BrowserPlatformLocation(ɵɵinject(DOCUMENT));
207-
}

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,9 +1994,6 @@
19941994
{
19951995
"name": "subsetMatchOptions"
19961996
},
1997-
{
1998-
"name": "supportsState"
1999-
},
20001997
{
20011998
"name": "switchMap"
20021999
},

0 commit comments

Comments
 (0)