如何将查询参数添加到routerLink?
@RouteConfig { {path: '/search',name: 'Search',component: SearchCmp} }
假设我要路由到/ search?q = asdf,
<a [routerLink]= " [ '/Search',{q= 'asdf'}] ">Link 1</a>
this.router.navigate( ['Search',{ q: 'asdf'}]);
要么
<a href="/search?a=asdf"> Link 2 </a>
?
如果你需要某些东西作为/ search?q = asdf比你可以简单地使用:
原文链接:/angularjs/142971.html@RouteConfig { {path: '/search',component: SearchCmp} } //And to generate router Links use: <a [routerLink]="['/Search',{q:'asdf'}]">
这将生成href标签为< a href =“/ search”,但是点击锚标签将导致url / search?q = asdf.您可以使用以下方式在您的SearchCmp中获取此参数:
constructor(private _routeParams: RouteParams) { var queryParam = this._routeParams.get('q'); }