Angular route using route params

We can use route feature of angular to move from one component to another. The template way of using the route feature is as below.

<button class="btn btn-success" [routerLink]="['/dashboard', data1, data2, data3]">Continue</button>

We can route from `.ts` file using router navigate. In order to route from ts file you need to import Router from `@angular/router` and to make it available in our template to use we can defined it in the constructor.

import { Router } from '@angular/router';

constructor(
     private _router : Router
) {
}

ngOnInit() : void{
   this._router.navigate(['/dashboard', data1, data2, data3] );
}

Note: I have added 3 route params because the dashboard accepts 3 route data. Just like below.

  {
    path : 'dasboard/:data1/:data2/:data3',
    component : DashboardComponent,
    canActivate: [AuthGuard],
  },

Published
Categorized as Angular

By Santosh Kumar Shah

I am JavaScript developer.

Leave a comment

Your email address will not be published. Required fields are marked *