我正在试用新路由器(版本 3.0.0-alpha.7),想知道如何通过 routerLink 指令指定查询参数?
下面的 Router.navigate() 方法生成一个类似 http://localhost:3000/component-a?x=1 的 URL
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>
关于angular - 如何通过 routerLink 指令指定查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342198/