Volodymyr Humeniuk
Volodymyr Humeniuk

Reputation: 3791

Angular router with optional query parameters

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?

Upvotes: 4

Views: 6316

Answers (1)

Vova Bilyachat
Vova Bilyachat

Reputation: 19484

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

Upvotes: 6

Related Questions