Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular router with optional query parameters

Tags:

angular

router

I have router

{
  path: 'reset-password',
  component: ResetPasswordComponent,
}

And I want to be able to open it as a direct link (/reset-password), or with passed parameters (/reset-password?uid=gsSxc&code=DsdxFSd), and so when creating a router snapshot I want to see the passed parameters.

How can I do this? Do I need to create two different routers for this?

like image 372
Vladimir Humeniuk Avatar asked Sep 13 '25 00:09

Vladimir Humeniuk


1 Answers

You don't need to have separate route since all query params are always optional and you should handle required parameters inside of your component.

Or define your required parameters in url to be path: 'reset-password/:uid', and path optional parameters via query String reset-password/1234?queryString=true

like image 117
Vova Bilyachat Avatar answered Sep 14 '25 16:09

Vova Bilyachat