Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Angular2 Routerlink: add query parameters

How can I add query parameters to routerLink?

@RouteConfig {
   {path: '/search',   name: 'Search', component: SearchCmp}
}  

Let' say I want to route to /search?q=asdf,

<a [routerLink]= " [ '/Search' , {q= 'asdf'}] ">Link 1</a>

this resolves to /search .

Is there a way to add query parameters without using:

this.router.navigate( ['Search', { q: 'asdf'}]);

or

<a href="/search?a=asdf"> Link 2 </a>

?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If u need something as /search?q=asdf than you can simply use:

@RouteConfig {
   {path: '/search',   name: 'Search', component: SearchCmp}
}

//And to generate router Links use:

<a [routerLink]="['/Search']" [queryParams]="{q:'asdf'}"></a>

This will generate the href tag as <a href="/search" but on clicking the anchor tag will lead you to url /search?q=asdf. [queryParams] will let you add the query params with "?", otherwise they will be appended by ";". You can get this parameter in your SearchCmp using:

constructor(private _routeParams: RouteParams) {
   var queryParam = this._routeParams.get('q');
}
over 4 years ago · Santiago Trujillo Report

0

OP (Original Poster) asked how to add query parameters via router link, not a router parameters as @SaUrAbH MaUrYa answered.

To add query parameters you need to use [queryParams] binding:

<a [routerLink]="['/users']" [queryParams]="{ page: 1 }">next page</a>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!