on click route to a component angular code example
Example 1: add a route to a buttoin in angular
<button type="button" class="btn btn-primary-outline pull-right" (click)="btnClick();"><i class="fa fa-plus"></i> Add</button>
import { Router } from '@angular/router';
constructor(private router: Router) {
}
btnClick= function () {
this.router.navigateByUrl('/user');
};
Example 2: angular navigate using component
import {Router} from '@angular/router';
export class Component{
constructor(private route:Router){}
go(){
this.route.navigate(['/page']);
}
}
Example 3: ng router link
<a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
link to user component
</a>
Example 4: how to add changes every time you route navigate to page in angular
import { Router,NavigationStart} from '@angular/router';
constructor(private router: Router){}
ngOnInit(){
this.router.events.subscribe(event =>{
if (event instanceof NavigationStart){
}
})
}