I'm encountering an issue when attempting to navigate to a route with an ID argument using the router.
Here's the code snippet from my component:
import { Router } from '@angular/router';
...
constructor(private router: Router) { }
...
public create() {
...
this.router.navigate(['/category/edit', id]);
}
This results in an error:
Error: Cannot match any routes. URL Segment: 'category/edit;id=11'
at ApplyRedirects.noMatchError (router.js:1719)
...
Interestingly, when I include the same logic in the template, it works perfectly fine:
<tbody>
<tr *ngFor="let category of model">
<td>{{category.name}}</td>
<td>{{category.code}}</td>
<td>
<button type="button" class="btn btn-outline-primary" [routerLink]="['/category/edit', category.id]">Edit</button>
</td>
</tr>
</tbody>
Here is how my route is defined:
{
path: 'category/edit/:id',
component: EditComponent,
resolve: {
model: CategoryResolver
}
}
I've tried with and without the resolver, but unfortunately, it doesn't seem to work either way.
My Angular version is 5.2.0 and CLI version is 1.6.5.