Home:ALL Converter>Angular4 - Routing with optional parameters and query parameters

Angular4 - Routing with optional parameters and query parameters

Ask Time:2017-07-28T18:13:14         Author:Ramadurgarao

Json Formatter

In angular4 routing, i am trying navigate to specific path with optional parameters but it not navigating to the correct path, Please see the below code

routes i have configured as

{ path:"login",component:"LoginComponent"},
 {path:"register",component:"RegisterComponent"},
 {path:"**",redirectTo:"register"}

i am routing to login as below this.router.navigate(["login",{optionalParam:"param"}]) but this is navigating to Register, i could observe in router debugging as url Redirects from "login;optionalParam=param" to "register". what could be the issue, i am facing same issue with queryParameters also.

Author:Ramadurgarao,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45370764/angular4-routing-with-optional-parameters-and-query-parameters
yy