DEV Community

Discussion on: Angular - How to pass arrays via Query Parameters

Collapse
 
shane profile image
Shane McGowan

You are confusing route params with query params.

/componentb/:ids will only match on /componentb/1 etc but not /componentb.
In this scenario :ids is a ROUTE param, you need a query param.

You will need to change the route to

const routes: Routes = [
{ path: 'componentb', component: componentb }
];
Enter fullscreen mode Exit fullscreen mode

and then navigate as follows

this.router.navigate(
    ['/componentb'],
    { queryParams: { ids:  ids} }
  );
Enter fullscreen mode Exit fullscreen mode

This uses query params. The url will be like this /componentb?ids=['a','b','c','d']