4

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.

1
  • routerLink is loading your component/modules etc via router-outlet without refreshing the page (you want this for an SPA), href is reloading your page/application or navigating to a different site etc.
    – Chris W.
    Commented Oct 30, 2018 at 15:34

2 Answers 2

2

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.

1

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.