0

With simple urls the folowing routes the following examples:

<a [routerLink]="['/foo/bar']"></a>

and

<a routerLink="/foo/bar"></a>

will make no difference. But even in the Angular Documentation we find examples like:

<a [routerLink]="['/user/bob']" preserveQueryParams preserveFragment>
  link to user component
</a>

So what is te advantage of using the attribute binding instead simple binding with routerLink directive in angular?

Josbel Luna
  • 2,574
  • 3
  • 17
  • 25
  • Possible [duplicate](https://stackoverflow.com/questions/41370760/difference-between-routerlink-and-routerlink) – Frederick Jun 19 '19 at 18:32
  • @Freddy I've seen that question before but not answer what is the advantage of using attribute binding sintax in simple urls – Josbel Luna Jun 19 '19 at 19:24

2 Answers2

1

Personally i try to use the same semantics for readability. Since i'm using [routerLink] at least once, i'll keep using it rather than routerLink, but both work obviousky ;)

lovis91
  • 1,988
  • 2
  • 14
  • 24
1

For simple urls, no need to use [routerLink]. But if the url is more complicated, I think [routerLink] is better. For example, you can use [routerLink]="['/user', 'bob', 5, ...]" instead of concatenate in normal way.

hamed
  • 7,939
  • 15
  • 60
  • 114