I want to have multiple functions in my appication activated through different parameters. The problem is that I have to distinguish between the routes. At the moment I need
You cannot map two path with the same exact segments as parameter. However, you can manually dispatch to the correct component. You can for exemple use this code.
export const EmployeeManagementRoutes: RouterConfig = [
{
path: 'employee-management',
component: EmployeeManagementComponent,
children: [
{
path: '',
component: EmployeeManagementTableComponent,
pathMatch: 'full'
},
{
path: ':type/:param',
component: EmployeeManagementTableComponent
}
]
}
];
this.route.params.subscribe(
params => {
this.logger.log("Param "+params);
let type = params['type'];
this.logger.log("Type "+type);
let p = params['params'];
if(type === "employee"){
if(p.match(/\d+/)){
let id = +p;
this.logger.log("ID "+id);
this.editEmployee(id);
} else {
let option = p;
this.logger.log("Option "+option);
this.doEmployeeOption(option);
}
}else if(type === "department"){
if(p){
let option = p;
this.logger.log("Option "+option);
this.doDepartmentOption(option);
}
}
},
//Error
err => this.logger.error(err),
//Complete
() => {}
);