Angular 2 routes load another component based on parameter type

I need to load different components depending on the type of route parameter. if route parameters are string then load one component as shown below,

{ path: 'care/action/:string',component: StringComponent},

if the route parameters are a number then load another component as shown below

{ path: 'care/action/:number', component: NumberComponent},

Note that the URL will remain the same, only the type of the parameter will change.

How do you achieve this?

Thanks in advance.

+3


source to share


1 answer


You might want to use the matcher property in your route configurations and pass the appropriate function to it. The matcher function will use a regular expression to check if there is a string (for a string route) or a number (for a number).



+1


source







All Articles