feat(common): provide replacement for AngularJS $location service (#30055)

This commit provides a replacement for `$location`. The new service is written in Angular, and can be consumed into existing applications by using the downgraded version
of the provider.

Prior to this addition, applications upgrading from AngularJS to Angular could get into a situation where AngularJS wanted to control the URL, and would often parse or se
rialize the URL in a different way than Angular. Additionally, AngularJS was alerted to URL changes only through the `$digest` cycle. This provided a buggy feedback loop
from Angular to AngularJS.

With this new `LocationUpgradeProvider`, the `$location` methods and events are provided in Angular, and use Angular APIs to make updates to the URL. Additionally, change
s to the URL made by other parts of the Angular framework (such as the Router) will be listened for and will cause events to fire in AngularJS, but will no longer attempt
 to update the URL (since it was already updated by the Angular framework).

This centralizes URL reads and writes to Angular and should help provide an easier path to upgrading AngularJS applications to Angular.

PR Close #30055
This commit is contained in:
Jason Aden
2019-04-23 07:16:08 -07:00
committed by Ben Lesh
parent f185ff3792
commit 4277600d5e
19 changed files with 1777 additions and 137 deletions

View File

@ -116,7 +116,6 @@ export declare class HashLocationStrategy extends LocationStrategy {
back(): void;
forward(): void;
getBaseHref(): string;
getState(): unknown;
onPopState(fn: LocationChangeListener): void;
path(includeHash?: boolean): string;
prepareExternalUrl(internal: string): string;
@ -167,13 +166,14 @@ export declare class KeyValuePipe implements PipeTransform {
}
export declare class Location {
constructor(platformStrategy: LocationStrategy);
constructor(platformStrategy: LocationStrategy, platformLocation: PlatformLocation);
back(): void;
forward(): void;
getState(): unknown;
go(path: string, query?: string, state?: any): void;
isCurrentPathEqualTo(path: string, query?: string): boolean;
normalize(url: string): string;
onUrlChange(fn: (url: string, state: unknown) => void): void;
path(includeHash?: boolean): string;
prepareExternalUrl(url: string): string;
replaceState(path: string, query?: string, state?: any): void;
@ -198,7 +198,6 @@ export declare abstract class LocationStrategy {
abstract back(): void;
abstract forward(): void;
abstract getBaseHref(): string;
abstract getState(): unknown;
abstract onPopState(fn: LocationChangeListener): void;
abstract path(includeHash?: boolean): string;
abstract prepareExternalUrl(internal: string): string;
@ -362,7 +361,6 @@ export declare class PathLocationStrategy extends LocationStrategy {
back(): void;
forward(): void;
getBaseHref(): string;
getState(): unknown;
onPopState(fn: LocationChangeListener): void;
path(includeHash?: boolean): string;
prepareExternalUrl(internal: string): string;
@ -378,6 +376,7 @@ export declare class PercentPipe implements PipeTransform {
export declare abstract class PlatformLocation {
abstract readonly hash: string;
abstract readonly hostname: string;
abstract readonly href: string;
abstract readonly pathname: string;
abstract readonly port: string;
abstract readonly protocol: string;