Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 6 queryParamsHandling difference between merge and perserve

Tags:

angular

In angular, What is the the difference between

queryParamsHandling:"merge" and queryParamsHandling:"preserve"?

like image 864
bat7 Avatar asked Nov 28 '18 10:11

bat7


People also ask

What is createUrlTree?

createUrlTree()link mode_edit code. Appends URL segments to the current URL tree to create a new URL tree.

What is query string in Angular?

Angular — Why you should start using query parameters to improve user friendliness. Query parameters (or query string) is a part of an URL that assigns values to specified parameters.

Which property of ActivatedRoute class helps read query parameter values?

Accessing Query Parameter Values The ActivatedRoute class has a queryParams property that returns an observable of the query parameters that are available in the current URL. There's also queryParamMap , which returns an observable with a paramMap object.


1 Answers

If you change the route from one url to another say from /firstUrl?name=bat7 to /secondUrl that time you need to say

this.router.navigate(['/secondUrl'], { queryParamsHandling: 'preserve' });

so that the queryParam "name" will not be lost

http://localhost:4200/secondUrl?name=bat7

and if you say merge like,

this.router.navigate(['/secondUrl/newVal'], { queryParams: { age: 'not-known'}, queryParamsHandling: 'merge' });

it would be like below

http://localhost:4200/secondUrl?name=bat7&age=not-known

The same query parameter can be taken to different routes and merged with needed params.

like image 121
Padmapriya Vishnuvardhan Avatar answered Oct 04 '22 03:10

Padmapriya Vishnuvardhan