Skip to content

Commit e93b3d2

Browse files
committed
fix(Location): make Location#platformStrategy:LocationStrategy property private
BREAKING CHANGE: Location#platformStrategy property was previously accidentaly exported as public If any application requires access to the current location strategy, it should be accessed via DI instead by injecting the LocationStrategy token. The likelyhood of anyone actually depending on this property is very low.
1 parent 7bc2d9a commit e93b3d2

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

modules/@angular/common/src/location/location.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,22 @@ export class Location {
5252
/** @internal */
5353
_baseHref: string;
5454

55-
constructor(public platformStrategy: LocationStrategy) {
56-
var browserBaseHref = this.platformStrategy.getBaseHref();
55+
/** @internal */
56+
_platformStrategy: LocationStrategy;
57+
58+
constructor(platformStrategy: LocationStrategy) {
59+
this._platformStrategy = platformStrategy;
60+
var browserBaseHref = this._platformStrategy.getBaseHref();
5761
this._baseHref = Location.stripTrailingSlash(_stripIndexHtml(browserBaseHref));
58-
this.platformStrategy.onPopState((ev) => {
62+
this._platformStrategy.onPopState((ev) => {
5963
ObservableWrapper.callEmit(this._subject, {'url': this.path(), 'pop': true, 'type': ev.type});
6064
});
6165
}
6266

6367
/**
6468
* Returns the normalized URL path.
6569
*/
66-
path(): string { return this.normalize(this.platformStrategy.path()); }
70+
path(): string { return this.normalize(this._platformStrategy.path()); }
6771

6872
/**
6973
* Normalizes the given path and compares to the current normalized path.
@@ -90,7 +94,7 @@ export class Location {
9094
if (url.length > 0 && !url.startsWith('/')) {
9195
url = '/' + url;
9296
}
93-
return this.platformStrategy.prepareExternalUrl(url);
97+
return this._platformStrategy.prepareExternalUrl(url);
9498
}
9599

96100
// TODO: rename this method to pushState
@@ -99,26 +103,26 @@ export class Location {
99103
* new item onto the platform's history.
100104
*/
101105
go(path: string, query: string = ''): void {
102-
this.platformStrategy.pushState(null, '', path, query);
106+
this._platformStrategy.pushState(null, '', path, query);
103107
}
104108

105109
/**
106110
* Changes the browsers URL to the normalized version of the given URL, and replaces
107111
* the top item on the platform's history stack.
108112
*/
109113
replaceState(path: string, query: string = ''): void {
110-
this.platformStrategy.replaceState(null, '', path, query);
114+
this._platformStrategy.replaceState(null, '', path, query);
111115
}
112116

113117
/**
114118
* Navigates forward in the platform's history.
115119
*/
116-
forward(): void { this.platformStrategy.forward(); }
120+
forward(): void { this._platformStrategy.forward(); }
117121

118122
/**
119123
* Navigates back in the platform's history.
120124
*/
121-
back(): void { this.platformStrategy.back(); }
125+
back(): void { this._platformStrategy.back(); }
122126

123127
/**
124128
* Subscribe to the platform's `popState` events.

modules/@angular/common/testing/location_mock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Injectable, EventEmitter} from '@angular/core';
22
import {ObservableWrapper} from '../src/facade/async';
33
import {Location} from '../index';
4+
import {LocationStrategy} from "../src/location/location_strategy";
45

56
/**
67
* A spy for {@link Location} that allows tests to fire simulated location events.
@@ -16,6 +17,8 @@ export class SpyLocation implements Location {
1617
_subject: EventEmitter<any> = new EventEmitter();
1718
/** @internal */
1819
_baseHref: string = '';
20+
/** @internal */
21+
_platformStrategy: LocationStrategy = null;
1922

2023
setInitialPath(url: string) { this._history[this._historyIndex].path = url; }
2124

@@ -101,8 +104,6 @@ export class SpyLocation implements Location {
101104
return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
102105
}
103106

104-
// TODO: remove these once Location is an interface, and can be implemented cleanly
105-
platformStrategy: any = null;
106107
normalize(url: string): string { return null; }
107108
}
108109

0 commit comments

Comments
 (0)