We have a requirement where depending on a static/global setting which will be set depending on the customer they want a different component to load for a route. The reason being they want slightly different functionality for a part of the application so we are going to write a component for each that caters for their scenarios. Is there a way to choose the component for a route dynamically/at runtime and keep the same route/url. Below is a simplified example of what we would like to achieve:
Component1:
@Component({
selector: 'customeronecomponent',
templateUrl: './customeronecomponent.component.html'
})
export class CustomerOneComponent implements OnInit {
}
Component2:
@Component({
selector: 'customertwocomponent',
templateUrl: './customertwocomponent.component.html'
})
export class CustomerTwoComponent implements OnInit {
}
Route:
{ path: 'home', component: CustomerComponentProvider },
In this instance the CustomerComponentProvider will internally check the setting and either return CustomerOneComponent or CustomerTwoComponent.
In angular2/4 is that the best way to do this or is it better to have a single component and on that component load the right component, the downside I see there is we would have three components instead of two for each route we need this.