📅  最后修改于: 2022-03-11 15:03:26.878000             🧑  作者: Mango
import {ActivatedRoute, Data} from "@angular/router";
const routes: Routes = [
{path: 'developer', component: EmployeeComponent, data: {emp_type: 'developer'}},
{path: 'tester', component: EmployeeComponent, data: {emp_type: 'tester'}},
{path: 'analyst', component: EmployeeComponent, data: {emp_type: 'analyst'}}
];
class EmployeeComponent {
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.data_subscription = this.route
.data
.subscribe(data: Data =>
console.log('Employee type passed via route is ' + data.emp_type)
);
}
ngOnDestroy() {
this.data_subscription.unsubscribe();
}
}