Using Angular 13, given a route, how can I get module name and controller name of the current activated route or url?
constructor(
private readonly router: Router,
private readonly activatedRoute: ActivatedRoute) {
}
ngOnInit(): void {
}
CodePudding user response:
Angular allows us to pass data to the route static or dynamic using the data property.
export const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'details', component: DetailsComponent, data :{ id: module.id, name:"ControllerName or Wherever Value"}},
];
You can read the information using the ActivatedRoute
export class HomeComponent implements OnInit {
constructor(private activatedroute:ActivatedRoute) {
}
ngOnInit() {
this.activatedroute.data.subscribe(data => {
console.log(data);
})
}
}
The official Angular documentation have great information about how to use. https://angular.io/api/router/ActivatedRoute