angular this.router.navigate code example
Example 1: angular navigate using component
import {Router} from '@angular/router';
export class Component{
constructor(private route:Router){}
go(){
this.route.navigate(['/page']);
}
}
Example 2: angular router navigate
goPlaces() {
this.router.navigate(['/', 'page-name']);
}
Example 3: angular routing url params
const appRoutes: Routes = [
{ path: 'crisis-center/:param1', component: CrisisListComponent },
{ path: 'hero/:param2', component: HeroDetailComponent },
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{ enableTracing: true }
)
],
...
})
export class AppModule { }
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){
}
})
}
Example 5: this.router.navigate
<a routerLink="/red-pill/neo">Go!</a>
Example 6: this.router.navigate
<a [routerLink]="['/', 'red-pill', {x: 'white-rabbit'}, 'neo']">
Param!
</a>