0

Is there a way to rewrite query params in Angular 2? I have an url like https://local_app/route?param1=1&param2=2 Can Angular an url to something like https://local_app/route/param1/1/param2/2 ?

  • You can use route guard in order to check if you have a query parameters in the url and then redirect to an appropriate url. Please, find guards details in the official Angular documentation: https://angular.io/guide/router – Viacheslav Moskalenko May 04 '18 at 08:02
  • Well, in query parameters you can send any data you want. A route like `https://local_app/route/param1/1/param2/2` will be interpreted by the router and you would have to define a route to match it `'route/param1/:p1/param2/:p2', component: XXX` but I don't think that this is a good use. – Fussel May 04 '18 at 08:05
  • It's not exactly what I asked about. Sorry, I didn't mentioned that I need params to be optional. So in some cases it can be https://local_app/route/param1/1, in some cases https://local_app/route/param2/2. Seems like there is no way to implement it. – Igor Zhukovich May 05 '18 at 23:04

0 Answers0