How to Preserve and Merge Query String Values?
This Article helps you to Understand, How to Preserve and Merge Query String Values?
Preserving Query Parameters
By default, the query parameters are lost on any subsequent navigation action. To prevent this, you can set queryParamsHandling to either 'preserve' or 'merge'.
Lets navigate to Product page with popular products
Now if we want to route visitors from a product page with the query parameter { order: 'popular' } to the /users page while keeping the query parameters, in-tact
This will result in a URL that resembles:
http://localhost:4200/users?order=popular
Merging Query Parameters
Now if we want to route visitors from a product page with the query parameter { order: 'popular' } to the /users page and while moving we want to merge a new query parameter { filter: 'new' }, we would use 'merge':
This will result in a URL that resembles:
http://localhost:4200/users?order=popular&filter=new