Html:
[routerLink]="['', {'scrollTo': '#contact'}]"
TS:
this.route.params.forEach((params: Params) => {
if (params['scrollTo']) {
// some code here
}
});
Error: EXCEPTION: Root segment cannot have matrix parameters
I can't have 'scrollTo' param in my routerLink?
It clearly appears on the angular 2 documentation: https://angular.io/docs/ts/latest/guide/router.html#!#appendix-link-parameters-array
EDIT:
Doesn't seem to complaint with : <a [routerLink]="['/crisis-center', { scrollTo: '#contact' }]">Crisis Center</a>
. But I need it with my '' root route.
Recently, it is done this way in Angular 5+:
<a [routerLink]="['/']" [queryParams]="{ 'tour': true }"> text </a>
Doing [routerLink]="['/', { 'tour': true' }]"> text </a>
would throw the error
The accepted answer is wrong, it sets query params (e.g ?myparam=true). To set matrix parameters (e.g ;myparam=15;foo=foo) the syntax is:
[routerLink]="['.', {'scrollTo': '#contact'}]"
Notice the period in the route. As is explained here:
https://github.com/angular/angular/issues/9505
That's how to set matrix parameters, and it fails with "''" because that's for the root route, which apparently won't allow matrix parameters-
The root segment cannot have matrix params. There are two reasons for this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With