EXCEPTION: Root segment cannot have matrix parameters
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 root segment cannot have matrix params. There are two reasons for this:
上一篇: “as”操作符的奇怪行为
下一篇: EXCEPTION:根段不能有矩阵参数