hilda_sonica_vish
hilda_sonica_vish

Reputation: 757

Routing with query params not working

I want to route to this page passing a param: http://localhost:4200/inventory/client?id=2

What I do is:

this.router.navigate(['/inventory/client',{id:this.vendorId}]);

But result involves a semicolon: http://localhost:4200/inventory/client;id=2

What should i do to change it to: http://localhost:4200/inventory/client?id=2

Upvotes: 2

Views: 15703

Answers (3)

Bharat chaudhari
Bharat chaudhari

Reputation: 534

Make sure while passing query params value should not be undefined.

      this.router.navigate(['/inventory/client',
         queryParams : 
              {
                id : (this.vendorId ? this.vendorId : '')
              }
            ]);
      

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222522

You should use queryParams

this.router.navigate(['/inventory/client'], { queryParams: { id: this.vendorId} });

Upvotes: 0

Olezt
Olezt

Reputation: 1738

Try this:

 this.router.navigate(['/inventory/client'], { queryParams: { id: this.vendorId} });

And have a look here: Passing Optional Parameters

Upvotes: 4

Related Questions