
This splits out `path` and `query` into separate params for `location.go` and related methods so that we can handle them properly in both `PathLocationStrategy` and `HashLocationStrategy`. This handles the problem of not reading query params to populate `Location` on the initial page load. Closes #3957 Closes #4225 Closes #3784
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
/**
|
|
* `LocationStrategy` is responsible for representing and reading route state
|
|
* from the the browser's URL. Angular provides two strategies:
|
|
* {@link HashLocationStrategy} (default) and {@link PathLocationStrategy}.
|
|
*
|
|
* This is used under the hood of the {@link Location} service.
|
|
*
|
|
* Applications should use the {@link Router} or {@link Location} services to
|
|
* interact with application route state.
|
|
*
|
|
* For instance, {@link HashLocationStrategy} produces URLs like
|
|
* `http://example.com#/foo`, and {@link PathLocationStrategy} produces
|
|
* `http://example.com/foo` as an equivalent URL.
|
|
*
|
|
* See these two classes for more.
|
|
*/
|
|
export abstract class LocationStrategy {
|
|
abstract path(): string;
|
|
abstract pushState(state: any, title: string, url: string, queryParams: string): void;
|
|
abstract forward(): void;
|
|
abstract back(): void;
|
|
abstract onPopState(fn: (_: any) => any): void;
|
|
abstract getBaseHref(): string;
|
|
}
|
|
|
|
export function normalizeQueryParams(params: string): string {
|
|
return (params.length > 0 && params.substring(0, 1) != '?') ? ('?' + params) : params;
|
|
}
|