Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 routes load different component based on type of parameter

I need to load different components based on the type of route parameter. if the route parameters is string then load one component like below,

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

if the route parameters is number then load another component like below

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

Please note that URL will remain same, only type of parameter will change.

How to achieve this?

Thanks in advance.

like image 387
Sameer K Avatar asked Nov 08 '22 21:11

Sameer K


1 Answers

You might want to leverage matcher property on your route configs and pass a matching function to it. Your matcher function would use regular expression to check if its a string (for string route) or number (for number).

like image 107
dee zg Avatar answered Nov 15 '22 12:11

dee zg