Reputation: 12855
This html button with routerLink attribute:
<button [routerLink]="['/projects', 'edit', project?.id]">E`enter code here`dit</button>
result in this link:
router-link="/projects,edit,1011"
I can not see from the documentation: https://angular.io/docs/ts/latest/api/router/index/RouterLink-directive.html
that I do something wrong.
This sample looks nearly like mine:
['/team', teamId, 'user', userName, {details: true}]
what do I wrong?
Upvotes: 1
Views: 1135
Reputation: 60518
You can associated code with a button click and then route with a method such as this:
onSaveComplete(message?: string): void {
if (message) {
this.messageService.addMessage(message);
}
this.reset();
// Navigate back to the product list
this.router.navigate(['/products']);
}
Upvotes: 2
Reputation: 17859
RouterLink' input is an array of strings, so in html:
<button [routerLink]="routerLink">My button</button>
TS:
routerLink = project.id ? ['/projects', 'edit', project.id] : ['/projects', 'edit']
Upvotes: 0
Reputation: 60518
As far as I know, the routerLink needs to be on a link element. Such as this:
<a class="btn btn-primary"
[routerLink]="['/productEdit', product.id]">
Edit
</a>
Upvotes: 1