I am creating an application with Angular and the Angular router. For navigating to one of the sub pages I need a required parameter in my url. How this should be done can be found in the Angular docs. But somehow this method is not working in my project.
Versions:
- @angular/core:
7.2.6
- @angular/router:
7.2.6
What I am trying to accomplish
I have a product list on one page and detail information on the second page. The routes of the pages are as follows:
- Main page:
/product-list
- Detail page:
/product-list/:id/info
The detail page is relative to the main page.
I've tried navigating to the page via:
this.router.navigate(
[':id/info', item.id],
{ relativeTo: this.activatedRoute }
)
But this results in an error from the Angular router: Error: Cannot match any routes. URL Segment: ':id/info/03-BR'
.
I reproduced this behavior in a stackblitz.
Manually changing the :id
I can navigate to the url if I replace the :id
myself, so using ['01-CE/info']
as a configuration redirects to the url. So it looks like the router doesn't work as it is described in the docs or am I doing something wrong?