Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing on button click in angular 5 [duplicate]

I need to route to a home component when the user clicks a button. I know how to do that using: <a href=””>, but not using: routerLink. Is there any way to do that using a button click event?

<a class="nav-item nav-link-edit" [routerLink]="['']">home</a>

The code above is how I use an <a href=""> tag to route.

like image 690
dilusha_dasanayaka Avatar asked Apr 03 '18 12:04

dilusha_dasanayaka


2 Answers

Yes, routerLink works on both anchor tags and button tags. You can do this:

<button class="nav-item nav-link-edit" [routerLink]="['']">home</button >
like image 111
Teddy Sterne Avatar answered Oct 05 '22 01:10

Teddy Sterne


routerLink will be working properly.

app.component.html:

<button class="nav-item nav-link-edit" [routerLink]="['Home']">Home</button >
like image 27
soumya cb Avatar answered Oct 04 '22 23:10

soumya cb