I would like to change fragment of the url programatically from the component but I'm failing to do so.
<a #linkComponent routerLink='home' fragment='part'>link</a>
@ViewChild('linkComponent') linkComponent;
this.linkComponent.????
Or maybe there is a different way maybe using Router
Modifying linkComponent will only change the element and I was after changing fragment URL. Here's an example in the documentation. Below I have a working solution.
@Component({
...
})
export class Cmp {
constructor( private router: Router ) { }
changeFragment() {
this.router.navigate( [ '/home' ], { fragment: 'part' } )
}
}
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