Seeking insights on how to craft a route with information stored in its URL parameters.
Here's an example of my route (app.routes.ts):
{path: 'results/:id', component: MyResultsComponent},
How I navigate to the route :
goToResultsPage(query: string) {
this.router.navigate(['results', query], { queryParams: { pageSize: 20 } });}
Additionally, there is a query parameter. I'm pondering on the most efficient and elegant way to retrieve this in my MyResultsComponent
. Currently, I have a sort of nested subscribe
structure:
ngOnInit() {
this.route
.params
.subscribe(params => {
this.query = params['id'];
this.route
.queryParams
.subscribe(queryParams => {
this.offset = queryParams['pageSize'];
#find entries this.entryService.findEntries(this.query, this.pageSize);
});
});
}
Subsequently, I aim to pass these parameters to my EntryService
to fetch the entries found.