我正在试验新的路由器(版本 3.0.0-alpha.7),想知道如何通过 routerLink 指令指定查询参数?
下面的 Router.navigate() 方法生成一个类似的 URLhttp://localhost:3000/component-a?x=1
this.router.navigate(['/component-a'], {queryParams: {x: 1}});
但是,我不知道如何使用 routerLink 指令执行相同的操作。像下面这样的模板返回解析器错误...
<a [routerLink]="['/component-a'], {queryParams: {x: 1}}">Component A</a>
我能得到的最接近的东西是http://localhost:3000/component-a;x=1,它使用子路由的语法。
<a [routerLink]="['/component-a', {x:1}]">Component A</a>
你可以做这样的事情
<a [routerLink]="['/component-a']" [queryParams]="{x: 1}">Component A</a>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)