How to check route parameters in Angular2? For example, I have a route:
{path: 'artist/:id', component: ArtistInfoComponent}
All I want to do is check if the id
parameter is a valid number, and if so, just show the component. Otherwise, display the error message page.
I found Route Guard in Angular 2, but I think that this is not the best way to do validation, because I can have many different parameters for different pages and to write a separate Route Guard for all these pages is not what I want,
Is it possible to specify a regular expression for each route parameter?
UPD: Maybe there is a way to do a check on the request parameters? I mean, if I have this url: /search?q=blablabla&page=2
, how can I check if the page
parameter is valid? Is there any way to do this without a guard?
Taras source share