I wonder whether there is a good reason to set (or not to set) the href
attribute on internal links in an Angular 7 single-page application.
It works with or without, as Angular uses the routerLink
attribute.
Although Angular Router uses routerLink
directive, the href
attribute is still the only solution for external links, e.g. https://stackoverflow.com
.
Using both routerLink
and href
does not make any sense as long as the latter one gets overwritten by the routerLink
.
href
will reload the page, where as RouterLink
is a directive that just leaves the SPA state as is and brings the Component
attached to the route
in the router-outlet
I believe there are other subtle advantages like setting the routerLinkActive
routerLink
is loading your component/modules etc viarouter-outlet
without refreshing the page (you want this for an SPA),href
is reloading your page/application or navigating to a different site etc.