I am building a webapplication with angular 2 that uses routes. Because i'm new to angular I used to link to another component with the href
attribute like so:
<a href="localhost:4200/database/seed/1">link</a>
This works but this approach also makes the component take a whopping 3 and a half seconds to load!
When i do it the routerLink
way like so:
<a [routerLink]="['/database/seed/',1]">link</a>
It takes under half a second to load. I was wondering why this is so, both approaches basically do the same thing. They link to another page. Can anyone explain what causes the difference in loading speed? Thank you
Using href is causing your entire website to be reloaded.
When you use Angular's router
, base components do not need to be reloaded (index.html, styles.css, app.component.html, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With