'Cannot match route
So, for some reason it displays that it can't match any routes? when i have the route im using defined here;
{
path: 'categories',
component: CategoriesComponent,
},
{
path: 'categories/:id',
component: CategoryComponent,
}
and called here
edit(id: number){
this.router.navigate(['/', id]);
}
edit() is linked to a button
im not sure what im doing wrong but it displays the following error
core.mjs:6485 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: '9'
Error: Cannot match any routes. URL Segment: '9'
but when i redirect the url manually to
http://localhost:4200/dashboard/categories/9
it works fine, im very certain im just making a stupid mistake but it's like the devil is hiding it cs i literally cant find it.
Spare me the time im gonna take to find the mistake please.
im new to angular
Solution 1:[1]
Either use relativeTo (if it makes sense):
edit(id: number) {
this.router.navigate(['/', id], { relativeTo: this.route });
}
Or specify the route you want to navigate to with /categories:
edit(id: number) {
this.router.navigate(['/categories', id]);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pzaenger |
