1goProducts() {
2 this.router.navigate(['/products'], { queryParams: { order: 'popular' } });
3}
4
5http://localhost:4200/products?order=popular
6
7 constructor(private route: ActivatedRoute) { }
8
9 ngOnInit() {
10 this.route.queryParams
11 .filter(params => params.order)
12 .subscribe(params => {
13 console.log(params); // { order: "popular" }
14
15 this.order = params.order;
16 console.log(this.order); // popular
17 }
18 );
19 }
1import {Router} from '@angular/router'; // import router from angular router
2
3export class Component{ // Example component..
4 constructor(private route:Router){}
5
6 go(){
7 this.route.navigate(['/page']); // navigate to other page
8 }
9}
1
2 const appRoutes: Routes = [
3 { path: 'crisis-center/:param1', component: CrisisListComponent },
4 { path: 'hero/:param2', component: HeroDetailComponent },
5];
6
7@NgModule({
8 imports: [
9 RouterModule.forRoot(
10 appRoutes,
11 { enableTracing: true } // <-- debugging purposes only
12 )
13 // other imports here
14 ],
15 ...
16})
17export class AppModule { }
18
1// Place import at the top
2import { Router,NavigationStart} from '@angular/router';
3
4//Place the code below inside your class
5constructor(private router: Router){}
6
7ngOnInit(){
8 this.router.events.subscribe(event =>{
9 if (event instanceof NavigationStart){
10
11 }
12 })
13}