Thank you for the tutorial..!!
How do we define router path if we pass array of values with query param?
const routes: Routes = [ { path: 'componentb/:ids', component: componentb } ];
It is working fine if i pass array of parameters like below , With query param i am getting Cannot match any routes error.
const arrayOfValues = ['a','b','c','d']; const ids = JSON.stringify(arrayOfValues); this.router.navigate(['/componentb', ids])
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.
/componentb/:ids
/componentb/1
/componentb
:ids
You will need to change the route to
const routes: Routes = [ { path: 'componentb', component: componentb } ];
and then navigate as follows
this.router.navigate( ['/componentb'], { queryParams: { ids: ids} } );
This uses query params. The url will be like this /componentb?ids=['a','b','c','d']
/componentb?ids=['a','b','c','d']
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for the tutorial..!!
How do we define router path if we pass array of values with query param?
const routes: Routes = [
{ path: 'componentb/:ids', component: componentb }
];
It is working fine if i pass array of parameters like below , With query param i am getting Cannot match any routes error.
const arrayOfValues = ['a','b','c','d'];
const ids = JSON.stringify(arrayOfValues);
this.router.navigate(['/componentb', ids])
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
and then navigate as follows
This uses query params. The url will be like this
/componentb?ids=['a','b','c','d']