0

Its possible to clean url parameters during canActivate?

routing:

const routes: Routes = [
  {
    path: 'myRoute',
    component: MyRouteComponent,
    canActivate: [MyGuard]
  }

]

guard:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (not) {
  return false;
}

//clean url parameters ?

return true;

}

url: ../myRoute?p=1&p=2&p=N

after guard: ../myRoute?p=1

antia
  • 83
  • 2
  • 13
  • Check this https://stackoverflow.com/questions/43665206/angular2-how-to-clear-url-query-params-on-router-navigate – yazan Nov 05 '20 at 07:40
  • Just check, don't fall into an endless cycle of calling the same URL. You can redirect with `navigateByUrl` or `createUrlTree`. – Numichi Nov 05 '20 at 08:22
  • HI @Numichi but if I make the redirect with navigateByUrl or createUrlTre does not create a loop with the guard? – antia Nov 05 '20 at 09:02
  • It will infinity loop, if you dont handle it with any logic. You can do infinity loop with 2 guards too. Like: main -> A guard -> B guard -> A -> B -> inf. loop... Worth watching it how work your implementation. And I recommend return navigate than false. "false", it essentially loads nothing and doesn’t even navigate. – Numichi Nov 05 '20 at 13:12

0 Answers0