diff --git a/aio/content/guide/deprecations.md b/aio/content/guide/deprecations.md index a8879533b1..c8ccb0d826 100644 --- a/aio/content/guide/deprecations.md +++ b/aio/content/guide/deprecations.md @@ -43,7 +43,6 @@ v9 - v12 | `@angular/core` | [`RenderComponentType`](#core) | v11 | | `@angular/core` | [`WrappedValue`](#core) | v12 | | `@angular/forms` | [`ngModel` with reactive forms](#ngmodel-reactive) | v11 | -| `@angular/router` | [`preserveQueryParams`](#router) | v11 | | `@angular/upgrade` | [`@angular/upgrade`](#upgrade) | v11 | | `@angular/upgrade` | [`getAngularLib`](#upgrade-static) | v11 | | `@angular/upgrade` | [`setAngularLib`](#upgrade-static) | v11 | @@ -113,12 +112,6 @@ Tip: In the [API reference section](api) of this doc site, deprecated APIs are i | --- | ----------- | --------------------- | ----- | | [`ngModel` with reactive forms](#ngmodel-reactive) | [`FormControlDirective`](api/forms/FormControlDirective) | v6 | none | -{@a router} -### @angular/router - -| API | Replacement | Deprecation announced | Notes | -| --- | ----------- | --------------------- | ----- | -| [`preserveQueryParams`](api/router/UrlCreationOptions#preserveQueryParams) | [`queryParamsHandling`](api/router/UrlCreationOptions#queryParamsHandling) | v4 | none | {@a upgrade} ### @angular/upgrade diff --git a/goldens/public-api/router/router.d.ts b/goldens/public-api/router/router.d.ts index 054ac19075..be72c3083c 100644 --- a/goldens/public-api/router/router.d.ts +++ b/goldens/public-api/router/router.d.ts @@ -341,7 +341,7 @@ export declare class Router { urlHandlingStrategy: UrlHandlingStrategy; urlUpdateStrategy: 'deferred' | 'eager'; constructor(rootComponentType: Type | null, urlSerializer: UrlSerializer, rootContexts: ChildrenOutletContexts, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes); - createUrlTree(commands: any[], navigationExtras?: UrlCreationOptions): UrlTree; + createUrlTree(commands: any[], navigationExtras?: NavigationExtras): UrlTree; dispose(): void; getCurrentNavigation(): Navigation | null; initialNavigation(): void; @@ -378,7 +378,6 @@ export declare class RouterEvent { export declare class RouterLink implements OnChanges { fragment?: string; preserveFragment: boolean; - /** @deprecated */ set preserveQueryParams(value: boolean); queryParams?: Params | null; queryParamsHandling?: QueryParamsHandling | null; replaceUrl: boolean; @@ -411,7 +410,6 @@ export declare class RouterLinkWithHref implements OnChanges, OnDestroy { fragment?: string; href: string; preserveFragment: boolean; - /** @deprecated */ set preserveQueryParams(value: boolean); queryParams?: Params | null; queryParamsHandling?: QueryParamsHandling | null; replaceUrl: boolean; @@ -498,7 +496,6 @@ export declare class Scroll { export declare interface UrlCreationOptions { fragment?: string; preserveFragment?: boolean; - /** @deprecated */ preserveQueryParams?: boolean; queryParams?: Params | null; queryParamsHandling?: QueryParamsHandling | null; relativeTo?: ActivatedRoute | null; diff --git a/packages/router/src/directives/router_link.ts b/packages/router/src/directives/router_link.ts index 4b6a4129eb..01f782b6af 100644 --- a/packages/router/src/directives/router_link.ts +++ b/packages/router/src/directives/router_link.ts @@ -206,17 +206,6 @@ export class RouterLink implements OnChanges { } } - /** - * @deprecated As of Angular v4.0 use `queryParamsHandling` instead. - */ - @Input() - set preserveQueryParams(value: boolean) { - if ((typeof ngDevMode === 'undefined' || ngDevMode) && console && console.warn) { - console.warn('preserveQueryParams is deprecated!, use queryParamsHandling instead.'); - } - this.preserve = value; - } - /** @nodoc */ @HostListener('click') onClick(): boolean { @@ -234,7 +223,6 @@ export class RouterLink implements OnChanges { relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment, - preserveQueryParams: attrBoolValue(this.preserve), queryParamsHandling: this.queryParamsHandling, preserveFragment: attrBoolValue(this.preserveFragment), }); @@ -346,17 +334,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy { } } - /** - * @deprecated As of Angular v4.0 use `queryParamsHandling` instead. - */ - @Input() - set preserveQueryParams(value: boolean) { - if ((typeof ngDevMode === 'undefined' || ngDevMode) && console && console.warn) { - console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.'); - } - this.preserve = value; - } - /** @nodoc */ ngOnChanges(changes: SimpleChanges): any { this.updateTargetUrlAndHref(); @@ -399,7 +376,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy { relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment, - preserveQueryParams: attrBoolValue(this.preserve), queryParamsHandling: this.queryParamsHandling, preserveFragment: attrBoolValue(this.preserveFragment), }); diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index a3da353288..11d99bbca6 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -104,14 +104,6 @@ export interface UrlCreationOptions { */ fragment?: string; - /** - * **DEPRECATED**: Use `queryParamsHandling: "preserve"` instead to preserve - * query parameters for the next navigation. - * - * @deprecated since v4 - */ - preserveQueryParams?: boolean; - /** * How to handle query parameters in the router link for the next navigation. * One of: @@ -1104,35 +1096,21 @@ export class Router { * router.createUrlTree(['../../team/44/user/22'], {relativeTo: route}); * ``` */ - createUrlTree(commands: any[], navigationExtras: UrlCreationOptions = {}): UrlTree { - const { - relativeTo, - queryParams, - fragment, - preserveQueryParams, - queryParamsHandling, - preserveFragment - } = navigationExtras; - if ((typeof ngDevMode === 'undefined' || ngDevMode) && preserveQueryParams && console && - console.warn) { - console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.'); - } + createUrlTree(commands: any[], navigationExtras: NavigationExtras = {}): UrlTree { + const {relativeTo, queryParams, fragment, queryParamsHandling, preserveFragment} = + navigationExtras; const a = relativeTo || this.routerState.root; const f = preserveFragment ? this.currentUrlTree.fragment : fragment; let q: Params|null = null; - if (queryParamsHandling) { - switch (queryParamsHandling) { - case 'merge': - q = {...this.currentUrlTree.queryParams, ...queryParams}; - break; - case 'preserve': - q = this.currentUrlTree.queryParams; - break; - default: - q = queryParams || null; - } - } else { - q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null; + switch (queryParamsHandling) { + case 'merge': + q = {...this.currentUrlTree.queryParams, ...queryParams}; + break; + case 'preserve': + q = this.currentUrlTree.queryParams; + break; + default: + q = queryParams || null; } if (q !== null) { q = this.removeEmptyProps(q); diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 4884edf007..e7f6c7bae1 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -2137,7 +2137,7 @@ describe('Integration', () => { @Component({ selector: 'someRoot', template: - `Link` + `Link` }) class RootCmpWithLink { }