Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change fragment from component

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

like image 541
user1048282 Avatar asked Dec 15 '22 02:12

user1048282


1 Answers

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' } )
  }
}
like image 99
user1048282 Avatar answered Dec 28 '22 09:12

user1048282