Angular RouterLink queryParamsHandling for optional params

angularangular2-routing

Is there a clean way to merge the current optional queryParams with an additional optional queryParam on a link in the template?

Current url: /search;brand=Trek

Desired goto link: /search;brand=Trek;start=1 (startCount will be incremented)

I know Angular supports the ability to merge normal queryParams (https://angular.io/docs/ts/latest/api/router/index/RouterLink-directive.html), but I don't think it works with optional queryParams.

That's why this doesn't work:

<a class="nav-btn"
   queryParamsHandling="merge"
   [routerLink]="[ { start: startCount+1 } ]">
    Next Page
</a>

Any suggestions?

Best Answer

Try

<a class="nav-btn"
   queryParamsHandling="preserve" <--- instead of 'merge'
   [routerLink]="[ { start: startCount+1 } ]">
    Next Page
</a>