Sitelet https://github.com/angular/angular/commit/783a5bd
Skip to content

Commit 783a5bd

Browse files
josephperrottatscott
authored andcommitted
fix(router): remove preserveQueryParams symbol (#38762)
Remove preserveQueryParams as it was deprecated for removal in v4, use queryParamsHandling="preserve" instead. BREAKING CHANGE: preserveQueryParams has been removed, use queryParamsHandling="preserve" instead PR Close #38762
1 parent c635011 commit 783a5bd

5 files changed

Lines changed: 14 additions & 70 deletions

File tree

‎aio/content/guide/deprecations.md‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ v9 - v12
4343
| `@angular/core` | [`RenderComponentType`](#core) | <!--v7--> v11 |
4444
| `@angular/core` | [`WrappedValue`](#core) | <!--v10--> v12 |
4545
| `@angular/forms` | [`ngModel` with reactive forms](#ngmodel-reactive) | <!--v6--> v11 |
46-
| `@angular/router` | [`preserveQueryParams`](#router) | <!--v7--> v11 |
4746
| `@angular/upgrade` | [`@angular/upgrade`](#upgrade) | <!--v8--> v11 |
4847
| `@angular/upgrade` | [`getAngularLib`](#upgrade-static) | <!--v8--> v11 |
4948
| `@angular/upgrade` | [`setAngularLib`](#upgrade-static) | <!--v8--> v11 |
@@ -113,12 +112,6 @@ Tip: In the [API reference section](api) of this doc site, deprecated APIs are i
113112
| --- | ----------- | --------------------- | ----- |
114113
| [`ngModel` with reactive forms](#ngmodel-reactive) | [`FormControlDirective`](api/forms/FormControlDirective) | v6 | none |
115114

116-
{@a router}
117-
### @angular/router
118-
119-
| API | Replacement | Deprecation announced | Notes |
120-
| --- | ----------- | --------------------- | ----- |
121-
| [`preserveQueryParams`](api/router/UrlCreationOptions#preserveQueryParams) | [`queryParamsHandling`](api/router/UrlCreationOptions#queryParamsHandling) | v4 | none |
122115

123116
{@a upgrade}
124117
### @angular/upgrade

‎goldens/public-api/router/router.d.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export declare class Router {
341341
urlHandlingStrategy: UrlHandlingStrategy;
342342
urlUpdateStrategy: 'deferred' | 'eager';
343343
constructor(rootComponentType: Type<any> | null, urlSerializer: UrlSerializer, rootContexts: ChildrenOutletContexts, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes);
344-
createUrlTree(commands: any[], navigationExtras?: UrlCreationOptions): UrlTree;
344+
createUrlTree(commands: any[], navigationExtras?: NavigationExtras): UrlTree;
345345
dispose(): void;
346346
getCurrentNavigation(): Navigation | null;
347347
initialNavigation(): void;
@@ -378,7 +378,6 @@ export declare class RouterEvent {
378378
export declare class RouterLink implements OnChanges {
379379
fragment?: string;
380380
preserveFragment: boolean;
381-
/** @deprecated */ set preserveQueryParams(value: boolean);
382381
queryParams?: Params | null;
383382
queryParamsHandling?: QueryParamsHandling | null;
384383
replaceUrl: boolean;
@@ -411,7 +410,6 @@ export declare class RouterLinkWithHref implements OnChanges, OnDestroy {
411410
fragment?: string;
412411
href: string;
413412
preserveFragment: boolean;
414-
/** @deprecated */ set preserveQueryParams(value: boolean);
415413
queryParams?: Params | null;
416414
queryParamsHandling?: QueryParamsHandling | null;
417415
replaceUrl: boolean;
@@ -498,7 +496,6 @@ export declare class Scroll {
498496
export declare interface UrlCreationOptions {
499497
fragment?: string;
500498
preserveFragment?: boolean;
501-
/** @deprecated */ preserveQueryParams?: boolean;
502499
queryParams?: Params | null;
503500
queryParamsHandling?: QueryParamsHandling | null;
504501
relativeTo?: ActivatedRoute | null;

‎packages/router/src/directives/router_link.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,6 @@ export class RouterLink implements OnChanges {
206206
}
207207
}
208208

209-
/**
210-
* @deprecated As of Angular v4.0 use `queryParamsHandling` instead.
211-
*/
212-
@Input()
213-
set preserveQueryParams(value: boolean) {
214-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && <any>console && <any>console.warn) {
215-
console.warn('preserveQueryParams is deprecated!, use queryParamsHandling instead.');
216-
}
217-
this.preserve = value;
218-
}
219-
220209
/** @nodoc */
221210
@HostListener('click')
222211
onClick(): boolean {
@@ -234,7 +223,6 @@ export class RouterLink implements OnChanges {
234223
relativeTo: this.route,
235224
queryParams: this.queryParams,
236225
fragment: this.fragment,
237-
preserveQueryParams: attrBoolValue(this.preserve),
238226
queryParamsHandling: this.queryParamsHandling,
239227
preserveFragment: attrBoolValue(this.preserveFragment),
240228
});
@@ -346,17 +334,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
346334
}
347335
}
348336

349-
/**
350-
* @deprecated As of Angular v4.0 use `queryParamsHandling` instead.
351-
*/
352-
@Input()
353-
set preserveQueryParams(value: boolean) {
354-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && <any>console && <any>console.warn) {
355-
console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
356-
}
357-
this.preserve = value;
358-
}
359-
360337
/** @nodoc */
361338
ngOnChanges(changes: SimpleChanges): any {
362339
this.updateTargetUrlAndHref();
@@ -399,7 +376,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
399376
relativeTo: this.route,
400377
queryParams: this.queryParams,
401378
fragment: this.fragment,
402-
preserveQueryParams: attrBoolValue(this.preserve),
403379
queryParamsHandling: this.queryParamsHandling,
404380
preserveFragment: attrBoolValue(this.preserveFragment),
405381
});

‎packages/router/src/router.ts‎

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ export interface UrlCreationOptions {
104104
*/
105105
fragment?: string;
106106

107-
/**
108-
* **DEPRECATED**: Use `queryParamsHandling: "preserve"` instead to preserve
109-
* query parameters for the next navigation.
110-
*
111-
* @deprecated since v4
112-
*/
113-
preserveQueryParams?: boolean;
114-
115107
/**
116108
* How to handle query parameters in the router link for the next navigation.
117109
* One of:
@@ -1104,35 +1096,21 @@ export class Router {
11041096
* router.createUrlTree(['../../team/44/user/22'], {relativeTo: route});
11051097
* ```
11061098
*/
1107-
createUrlTree(commands: any[], navigationExtras: UrlCreationOptions = {}): UrlTree {
1108-
const {
1109-
relativeTo,
1110-
queryParams,
1111-
fragment,
1112-
preserveQueryParams,
1113-
queryParamsHandling,
1114-
preserveFragment
1115-
} = navigationExtras;
1116-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && preserveQueryParams && <any>console &&
1117-
<any>console.warn) {
1118-
console.warn('preserveQueryParams is deprecated, use queryParamsHandling instead.');
1119-
}
1099+
createUrlTree(commands: any[], navigationExtras: NavigationExtras = {}): UrlTree {
1100+
const {relativeTo, queryParams, fragment, queryParamsHandling, preserveFragment} =
1101+
navigationExtras;
11201102
const a = relativeTo || this.routerState.root;
11211103
const f = preserveFragment ? this.currentUrlTree.fragment : fragment;
11221104
let q: Params|null = null;
1123-
if (queryParamsHandling) {
1124-
switch (queryParamsHandling) {
1125-
case 'merge':
1126-
q = {...this.currentUrlTree.queryParams, ...queryParams};
1127-
break;
1128-
case 'preserve':
1129-
q = this.currentUrlTree.queryParams;
1130-
break;
1131-
default:
1132-
q = queryParams || null;
1133-
}
1134-
} else {
1135-
q = preserveQueryParams ? this.currentUrlTree.queryParams : queryParams || null;
1105+
switch (queryParamsHandling) {
1106+
case 'merge':
1107+
q = {...this.currentUrlTree.queryParams, ...queryParams};
1108+
break;
1109+
case 'preserve':
1110+
q = this.currentUrlTree.queryParams;
1111+
break;
1112+
default:
1113+
q = queryParams || null;
11361114
}
11371115
if (q !== null) {
11381116
q = this.removeEmptyProps(q);

‎packages/router/test/integration.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ describe('Integration', () => {
21372137
@Component({
21382138
selector: 'someRoot',
21392139
template:
2140-
`<router-outlet></router-outlet><a routerLink="/home" preserveQueryParams preserveFragment>Link</a>`
2140+
`<router-outlet></router-outlet><a routerLink="/home" queryParamsHandling="preserve" preserveFragment>Link</a>`
21412141
})
21422142
class RootCmpWithLink {
21432143
}

0 commit comments

Comments
 (0)