0

When I try to go 'localhost:4200/reset-password?token=asdsadas' Angular changes url to just 'localhost:4200/reset-password', so, I am not able to get query parameters from code.

Here is my routing settings:

const routes: Routes = [
  { path: '', redirectTo: '/register', pathMatch: 'full' },
  {
    path: 'login',
    component: LoginComponent,
    canActivate: [AnonymousGuard],
  },
  {
    path: 'register',
    component: RegisterComponent,
    canActivate: [AnonymousGuard],
  },
  {
    path: 'application',
    component: ApplicationFlowComponent,
    children: applicationFlowRoutes,
    canActivate: [AuthGuard],
  },
  {
    path: 'qflow',
    loadChildren: () => import('./questioneer-flow/questioneer-module.module').then((x) => x.QuestioneerModuleModule),
  },
  {
    path: 'reset-password-mail',
    component: ResetPasswordMailComponent,
  },
  {
    path: 'reset-password',
    component: ResetPasswordComponent,
    canActivate: [RequiredQueryParamsGuard],
    data: {
      requiredQueryParams: ['token']
    },
  },
  {
    path: 'oflow',
    component: OverviewAppFlowComponent,
  },
  {
    path: 'decline',
    component: DeclineComponent,
  }
];
8
  • Could you try using localhost:4200/reset-password/?token=asdsadas? Commented Jul 29, 2021 at 12:22
  • No, it redirects to simple localhost:4200/reset-password too Commented Jul 29, 2021 at 12:25
  • did you check the canActivate? Commented Jul 29, 2021 at 12:28
  • Yes, it happens not only in one route. It happens with the whole application. Commented Jul 29, 2021 at 12:31
  • 1
    Maybe this can help: stackoverflow.com/questions/48552993/…, if not.. Try set the url from reset-password to reset-password/:token and get it with route.params.subscribe Commented Jul 29, 2021 at 13:06

1 Answer 1

2

Change your reset password route in your routing file as below : -

{
    path: 'reset-password/:token',
    component: ResetPasswordComponent,
    canActivate: [RequiredQueryParamsGuard],
    data: {
        requiredQueryParams: ['token']
    },
}

Hope this would solve your issue.

Re:Yes, it happens not only in one route. It happens with the whole application - To solve this issue I suggest you to Refer this and change your routes accordingly - https://www.tektutorialshub.com/angular/angular-passing-optional-query-parameters-to-route/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.