Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - should it be routerLink="theRoute" or [routerLink]="['the route']"?

I am really confused whether I should be using

<a routerLink="/about">About</a>

or

<a [routerLink]="['/about']">About</a>
like image 535
user1354934 Avatar asked Feb 04 '26 01:02

user1354934


1 Answers

Both are correct.

<a routerLink="/about">About</a>

and

<a [routerLink]="'/about'">About</a>

pass a path as string

while

<a [routerLink]="['/about']">About</a>

passes an array of router commands.

Both are supported.

https://github.com/angular/angular/blob/9d9e9c6ff1eb37d54a6e4af0a88f05a41f75d7a9/modules/%40angular/router/src/directives/router_link.ts#L85

  @Input()
  set routerLink(data: any[]|string) {
like image 152
Günter Zöchbauer Avatar answered Feb 05 '26 21:02

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!