I am working with an Angular 6 project in which I have disabled/removed hash-location-strategy which removes # from URL.
due to this change the link having:
<li routerLinkActive="active">
<a [routerLink]="['/settings']">Contact Settings</a>
<ul class="child-link-sub">
<li>
<a href="#contactTypes">Contact Types</a>
</li>
</ul>
</li>
is no more working it just skips the current components URL and puts #contactTypes after localhost.
I found this github issue which should solve the issue using
<a [routerLink]="['/settings/']" fragment="contactTypes" >Contact Types</a>
which puts #contactTypes at the end of the URL but it doesn't scroll to the top of the browser.
Angular 6.1 comes with an option called
anchorScrollingthat lives in router module'sExtraOptions. As theanchorScrollingdefinition says:You can use it like that: